jkg012 commited on
Commit
ad67c84
·
verified ·
1 Parent(s): 42c5b1b

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +61 -0
  2. data.csv +0 -0
  3. requirements.txt +8 -0
app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pickle
3
+ import numpy as np
4
+ import pandas as pd
5
+ from sklearn.preprocessing import StandardScaler
6
+
7
+ # Load your trained model
8
+ with open("log_reg.pkl", "rb") as f:
9
+ model = pickle.load(f)
10
+
11
+ # Load or define your scaler (assumed you saved it similarly)
12
+ with open("scaler.pkl", "rb") as f:
13
+ scaler = pickle.load(f)
14
+
15
+ # Define the input features that your model uses, e.g.:
16
+ input_features = [
17
+ "Age", "Income", "Debt", "Debt_to_Income",
18
+ "Payment_History_Num", "Is_Employed",
19
+ # ... add other numeric features or encoded categorical features needed
20
+ ]
21
+
22
+ def predict_creditworthiness(age, income, debt, payment_history, employment_status):
23
+ # Feature engineering like in training
24
+ debt_to_income = debt / (income + 1)
25
+ payment_map = {"Bad": 0, "Average": 1, "Good": 2}
26
+ payment_num = payment_map.get(payment_history, 1)
27
+ employed_num = 1 if employment_status == "Employed" else 0
28
+
29
+ # Create feature array in correct order expected by model
30
+ input_data = np.array([[age, income, debt, debt_to_income, payment_num, employed_num]])
31
+
32
+ # Scale features
33
+ input_scaled = scaler.transform(input_data)
34
+
35
+ # Predict probability and class
36
+ proba = model.predict_proba(input_scaled)[0, 1]
37
+ pred_class = model.predict(input_scaled)[0]
38
+
39
+ credit_status = "Good Credit" if pred_class == 1 else "Bad Credit"
40
+ return f"Prediction: {credit_status} (Probability of good credit: {proba:.2f})"
41
+
42
+ # Gradio input widgets reflecting your features
43
+ iface = gr.Interface(
44
+ fn=predict_creditworthiness,
45
+ inputs=[
46
+ gr.Number(label="Age", value=30, precision=0),
47
+ gr.Number(label="Income", value=50000, precision=2),
48
+ gr.Number(label="Debt", value=5000, precision=2),
49
+ gr.Dropdown(label="Payment History", choices=["Bad", "Average", "Good"], value="Average"),
50
+ gr.Radio(label="Employment Status", choices=["Employed", "Unemployed"], value="Employed"),
51
+ ],
52
+ outputs="text",
53
+ title="Credit Scoring Model (Logistic Regression)",
54
+ description="Enter your financial details to predict creditworthiness."
55
+ )
56
+
57
+ if __name__ == "__main__":
58
+ iface.launch()
59
+
60
+
61
+
data.csv ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ pandas
2
+ numpy
3
+ flask
4
+ matplotlib
5
+ seaborn
6
+ gradio
7
+ sklearn.preprocessing
8
+ scikit-learn