Spaces:
Sleeping
Sleeping
import pandas as pd | |
import numpy as np | |
import seaborn as sns | |
import matplotlib.pyplot as plt | |
from sklearn.model_selection import train_test_split | |
from sklearn.neighbors import KNeighborsClassifier | |
import gradio as gr | |
# Load data | |
nexus_bank = pd.read_csv('nexus_bank_dataa.csv') | |
# Preprocessing | |
X = nexus_bank[['salary', 'dependents']] | |
y = nexus_bank['defaulter'] | |
# Train-test split | |
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.15, random_state=90) | |
# Model training | |
knn_classifier = KNeighborsClassifier() | |
knn_classifier.fit(X_train, y_train) | |
# Prediction function | |
def predict_defaulter(salary, dependents): | |
input_data = [[salary, dependents]] | |
knn_predict = knn_classifier.predict(input_data) | |
return "Yes! It's a Defaulter" if knn_predict[0] == 1 else "No! It's not a Defaulter" | |
# Interface | |
interface = gr.Interface( | |
fn=predict_defaulter, | |
inputs=["number", "number"], | |
outputs="text", | |
title="Defaulter Prediction", | |
descripation="Predicting Defaulters An intuitive app leveraging machine learning to forecast potential defaulters based on financial attributes. Simply input salary and number of dependents to receive instant predictions. Streamlining risk assessment and decision-making processes in financial domains with just a few clicks." | |
) | |
# Launch the interface | |
interface.launch() | |