Spaces:
Runtime error
Runtime error
Tihsrah-CD
commited on
Commit
•
fc7772a
1
Parent(s):
144eed7
Publishing application
Browse files- Random_Forest.joblib +3 -0
- app.py +98 -0
- encoders.joblib +3 -0
- requirements.txt +4 -0
Random_Forest.joblib
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1cc06f00e19dfafa3cb069ea4ac8fa532d1fbfea2f655b88bc1b28e6f56469e7
|
3 |
+
size 32612
|
app.py
ADDED
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import joblib
|
2 |
+
import streamlit as st
|
3 |
+
import pandas as pd
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
def main():
|
7 |
+
st.title("Credit Application Form")
|
8 |
+
|
9 |
+
Occupation = st.selectbox("Occupation", options=["Accountant", "Architect", "Developer", "Doctor", "Engineer",
|
10 |
+
"Entrepreneur", "Journalist", "Lawyer", "Manager", "Mechanic",
|
11 |
+
"Media_Manager", "Musician", "Scientist", "Teacher", "Writer"])
|
12 |
+
Payment_Behaviour = st.selectbox("Payment Behavior",
|
13 |
+
options=["High_spent_Large_value_payments", "High_spent_Medium_value_payments",
|
14 |
+
"High_spent_Small_value_payments", "Low_spent_Large_value_payments",
|
15 |
+
"Low_spent_Medium_value_payments", "Low_spent_Small_value_payments"])
|
16 |
+
|
17 |
+
|
18 |
+
Month = st.select_slider("Month", options=[1, 2, 3, 4, 5, 6, 7, 8])
|
19 |
+
Num_Bank_Accounts = st.select_slider("Number of Bank Accounts", options=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
|
20 |
+
Num_Credit_Card = st.select_slider("Number of Credit Cards", options=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
|
21 |
+
Num_of_Loan = st.select_slider("Number of Loan", options=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
|
22 |
+
Interest_Rate = st.select_slider("Interest Rate", np.arange(1, 35, 1))
|
23 |
+
# Interest_Rate = st.number_input("Interest Rate", min_value=1, max_value=34)
|
24 |
+
|
25 |
+
Age = st.number_input("Age")
|
26 |
+
Annual_Income = st.number_input("Annual Income", value=1.0)
|
27 |
+
Monthly_Inhand_Salary = st.number_input("Monthly Inhand Salary")
|
28 |
+
|
29 |
+
Num_of_Delayed_Payment = st.number_input("Number of Delayed Payments", format='%u', value=0)
|
30 |
+
Changed_Credit_Limit = st.number_input("Changed Credit Limit")
|
31 |
+
Num_Credit_Inquiries = st.number_input("Number of Credit Inquiries", format='%u', value=0)
|
32 |
+
Credit_History_Age = st.number_input("Credit History Age")
|
33 |
+
|
34 |
+
Outstanding_Debt = st.number_input("Outstanding Debt")
|
35 |
+
Credit_Utilization_Ratio = st.number_input("Credit Utilization Ratio")
|
36 |
+
Total_EMI_per_month = st.number_input("Total EMI per Month")
|
37 |
+
Amount_invested_monthly = st.number_input("Amount Invested Monthly")
|
38 |
+
Monthly_Balance = st.number_input("Monthly_Balance")
|
39 |
+
|
40 |
+
Credit_Mix = st.radio("Credit Mix", options=("Bad", "Good", "Standard"), index=1)
|
41 |
+
|
42 |
+
submit_button = st.button("Submit")
|
43 |
+
|
44 |
+
if submit_button:
|
45 |
+
# Process the form data
|
46 |
+
process_form_data(Month, Age, Occupation, Annual_Income, Monthly_Inhand_Salary, Num_Bank_Accounts,
|
47 |
+
Num_Credit_Card, Interest_Rate, Num_of_Loan,
|
48 |
+
Num_of_Delayed_Payment, Changed_Credit_Limit, Num_Credit_Inquiries, Credit_Mix,
|
49 |
+
Payment_Behaviour, Credit_History_Age, Outstanding_Debt,
|
50 |
+
Credit_Utilization_Ratio, Total_EMI_per_month, Amount_invested_monthly, Monthly_Balance)
|
51 |
+
|
52 |
+
def process_form_data(Month, Age, Occupation, Annual_Income, Monthly_Inhand_Salary, Num_Bank_Accounts,
|
53 |
+
Num_Credit_Card, Interest_Rate, Num_of_Loan, Num_of_Delayed_Payment,
|
54 |
+
Changed_Credit_Limit, Num_Credit_Inquiries, Credit_Mix, Payment_Behaviour,
|
55 |
+
Credit_History_Age, Outstanding_Debt, Credit_Utilization_Ratio, Total_EMI_per_month,
|
56 |
+
Amount_invested_monthly, Monthly_Balance):
|
57 |
+
|
58 |
+
# Feature Engineering
|
59 |
+
|
60 |
+
Monthly_Savings = Monthly_Inhand_Salary - Annual_Income / 12
|
61 |
+
Total_Accounts = int(Num_Bank_Accounts) + int(Num_Credit_Card)
|
62 |
+
Savings_to_Income_Ratio = Monthly_Savings / Annual_Income
|
63 |
+
|
64 |
+
encoders = joblib.load('v2\encoders.joblib')
|
65 |
+
model = joblib.load('v2\Random_Forest.joblib')
|
66 |
+
|
67 |
+
dataDict = {"Month": Month, 'Occupation': Occupation, 'Num_Bank_Accounts': Num_Bank_Accounts, 'Num_Credit_Card': Num_Credit_Card,
|
68 |
+
'Interest_Rate': Interest_Rate, 'Num_of_Loan': Num_of_Loan, 'Credit_Mix': Credit_Mix, 'Credit_History_Age': Credit_History_Age,
|
69 |
+
'Num_of_Delayed_Payment': Num_of_Delayed_Payment, 'Payment_of_Min_Amount': Num_of_Delayed_Payment,
|
70 |
+
'Payment_Behaviour': Payment_Behaviour, 'Age': Age, 'Annual_Income': Annual_Income, 'Monthly_Inhand_Salary': Monthly_Inhand_Salary,
|
71 |
+
'Outstanding_Debt': Outstanding_Debt, 'Credit_Utilization_Ratio': Credit_Utilization_Ratio,'Changed_Credit_Limit': Changed_Credit_Limit,
|
72 |
+
'Num_Credit_Inquiries': Num_Credit_Inquiries, 'Total_EMI_per_month': Total_EMI_per_month, 'Amount_invested_monthly': Amount_invested_monthly,
|
73 |
+
'Monthly_Balance': Monthly_Balance, 'Total_Accounts': Total_Accounts, 'Savings_to_Income_Ratio': Savings_to_Income_Ratio}
|
74 |
+
|
75 |
+
df = pd.DataFrame([dataDict])
|
76 |
+
cols = ['Month', 'Num_Bank_Accounts', 'Num_Credit_Card', 'Interest_Rate', 'Num_of_Loan']
|
77 |
+
df[cols] = df[cols].astype(int)
|
78 |
+
|
79 |
+
decodedData = df.copy()
|
80 |
+
for col in ['Occupation', 'Payment_Behaviour', 'Credit_Mix']:
|
81 |
+
encoder = encoders[col]
|
82 |
+
decodedData[col] = encoder.transform(decodedData[col])
|
83 |
+
|
84 |
+
result = model.predict(decodedData)
|
85 |
+
result = encoders['Credit_Score'].inverse_transform(result)
|
86 |
+
|
87 |
+
st.write(df)
|
88 |
+
st.write(decodedData)
|
89 |
+
st.write(result)
|
90 |
+
|
91 |
+
|
92 |
+
if __name__ == "__main__":
|
93 |
+
# Load the models and encoders
|
94 |
+
encoders = joblib.load('spaces\encoders.joblib')
|
95 |
+
model = joblib.load('spaces\Random_Forest.joblib')
|
96 |
+
|
97 |
+
# Run the Streamlit app
|
98 |
+
main()
|
encoders.joblib
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:afdff248e3aad36bd5bb1c6fcc74d58fada95659211f7964fa3363be7a52e37b
|
3 |
+
size 10010
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit==0.90.0
|
2 |
+
pandas
|
3 |
+
numpy
|
4 |
+
joblib
|