Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import numpy as np
|
3 |
+
import seaborn as sns
|
4 |
+
import matplotlib.pyplot as plt
|
5 |
+
from sklearn.model_selection import train_test_split
|
6 |
+
from sklearn.neighbors import KNeighborsClassifier
|
7 |
+
import gradio as gr
|
8 |
+
|
9 |
+
# Load data
|
10 |
+
nexus_bank = pd.read_csv('nexus_bank_dataa.csv')
|
11 |
+
|
12 |
+
# Preprocessing
|
13 |
+
X = nexus_bank[['salary', 'dependents']]
|
14 |
+
y = nexus_bank['defaulter']
|
15 |
+
|
16 |
+
# Train-test split
|
17 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.15, random_state=90)
|
18 |
+
|
19 |
+
# Model training
|
20 |
+
knn_classifier = KNeighborsClassifier()
|
21 |
+
knn_classifier.fit(X_train, y_train)
|
22 |
+
|
23 |
+
# Prediction function
|
24 |
+
def predict_defaulter(salary, dependents):
|
25 |
+
input_data = [[salary, dependents]]
|
26 |
+
knn_predict = knn_classifier.predict(input_data)
|
27 |
+
return "Yes! It's a Defaulter" if knn_predict[0] == 1 else "No! It's not a Defaulter"
|
28 |
+
|
29 |
+
# Interface
|
30 |
+
interface = gr.Interface(
|
31 |
+
fn=predict_defaulter,
|
32 |
+
inputs=["number", "number"],
|
33 |
+
outputs="text",
|
34 |
+
title="Defaulter Prediction"
|
35 |
+
)
|
36 |
+
|
37 |
+
# Launch the interface
|
38 |
+
interface.launch()
|