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", | |
| description="This app predicts whether an individual is likely to default based on their salary and number of dependents. Input the respective values and get instant predictions." | |
| ) | |
| # Launch the interface | |
| interface.launch() | |