Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ from joblib import load
|
|
4 |
|
5 |
# Load the trained model and scaler
|
6 |
model = load('loandefaulter.joblib')
|
7 |
-
|
8 |
|
9 |
# Define numerical features for scaling
|
10 |
num_features = [
|
@@ -12,19 +12,30 @@ num_features = [
|
|
12 |
]
|
13 |
|
14 |
# Create the Streamlit app
|
15 |
-
st.
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
loan_amnt_by_income = loan_amnt / (annual_inc + 1)
|
29 |
|
30 |
# Create a DataFrame for the input
|
@@ -41,9 +52,14 @@ input_data = pd.DataFrame({
|
|
41 |
'loan_amnt_by_income': [loan_amnt_by_income]
|
42 |
})
|
43 |
|
44 |
-
|
|
|
45 |
|
46 |
# Predict using the model
|
47 |
if st.button('Predict'):
|
48 |
prediction = model.predict(input_data)
|
49 |
-
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
# Load the trained model and scaler
|
6 |
model = load('loandefaulter.joblib')
|
7 |
+
scaler = load('scaler.joblib')
|
8 |
|
9 |
# Define numerical features for scaling
|
10 |
num_features = [
|
|
|
12 |
]
|
13 |
|
14 |
# Create the Streamlit app
|
15 |
+
st.set_page_config(page_title='Loan Default Prediction', layout='wide')
|
16 |
+
|
17 |
+
# App title and description
|
18 |
+
st.markdown("""
|
19 |
+
<style>
|
20 |
+
.title { font-size: 36px; font-weight: bold; color: #2E86C1; }
|
21 |
+
.description { font-size: 20px; color: #34495E; }
|
22 |
+
.input-container { margin-top: 20px; }
|
23 |
+
.slider-container { margin: 10px 0; }
|
24 |
+
</style>
|
25 |
+
<div class="title">Loan Default Prediction</div>
|
26 |
+
<div class="description">Enter the loan details below to get a prediction on whether the loan will be defaulted.</div>
|
27 |
+
""", unsafe_allow_html=True)
|
28 |
+
|
29 |
+
# Input fields with sliders
|
30 |
+
loan_amnt = st.slider('Loan Amount', min_value=0.0, max_value=1000000.0, step=1000.0, value=10000.0)
|
31 |
+
int_rate = st.slider('Interest Rate (%)', min_value=0.0, max_value=30.0, step=0.1, value=5.0)
|
32 |
+
installment = st.slider('Installment', min_value=0.0, max_value=10000.0, step=10.0, value=200.0)
|
33 |
+
annual_inc = st.slider('Annual Income', min_value=0.0, max_value=1000000.0, step=1000.0, value=50000.0)
|
34 |
+
dti = st.slider('Debt-to-Income Ratio', min_value=0.0, max_value=100.0, step=0.1, value=15.0)
|
35 |
+
revol_bal = st.slider('Revolving Balance', min_value=0.0, max_value=500000.0, step=100.0, value=10000.0)
|
36 |
+
revol_util = st.slider('Revolving Utilization (%)', min_value=0.0, max_value=100.0, step=0.1, value=30.0)
|
37 |
+
total_acc = st.slider('Total Accounts', min_value=0, max_value=100, step=1, value=10)
|
38 |
+
mort_acc = st.slider('Mortgage Accounts', min_value=0, max_value=10, step=1, value=1)
|
39 |
loan_amnt_by_income = loan_amnt / (annual_inc + 1)
|
40 |
|
41 |
# Create a DataFrame for the input
|
|
|
52 |
'loan_amnt_by_income': [loan_amnt_by_income]
|
53 |
})
|
54 |
|
55 |
+
# Scale the input data
|
56 |
+
input_data[num_features] = scaler.transform(input_data[num_features])
|
57 |
|
58 |
# Predict using the model
|
59 |
if st.button('Predict'):
|
60 |
prediction = model.predict(input_data)
|
61 |
+
result = "Defaulted" if prediction[0] == 1 else "Not Defaulted"
|
62 |
+
color = "red" if prediction[0] == 1 else "green"
|
63 |
+
st.markdown(f"""
|
64 |
+
<div style="font-size: 24px; color: {color}; font-weight: bold;">Prediction: {result}</div>
|
65 |
+
""", unsafe_allow_html=True)
|