-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
44 lines (38 loc) · 1.58 KB
/
app.py
File metadata and controls
44 lines (38 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import streamlit as st
import pandas as pd
import joblib
model = joblib.load("extra_trees_credit_model.pkl")
encoder = {
col: joblib.load(f"{col}_le.pkl")
for col in ["Sex", "Housing", "Saving accounts", "Checking account", "Purpose"]
}
st.title("Credit Risk Prediction App")
st.write("Enter applicant information to predict if the credit risk is good or bad")
age = st.number_input("Age", min_value=18, max_value=100, value=30)
sex = st.selectbox("Sex", ["male", "female"])
job = st.number_input("jobs(0-3)", min_value=0, max_value=3, value=1)
housing = st.selectbox("Housing", ["own", "rent", "free"])
saving_accounts = st.selectbox(
"Saving accounts", ["little", "moderate", "rich", "quite rich"]
)
checking_account = st.selectbox(
"Checking account", ["little", "moderate", "rich", "quite rich"]
)
credit_amount = st.number_input("Credit amount", min_value=0, value=1000)
duration = st.number_input("Duration (months)", min_value=1, value=12)
input_df = pd.DataFrame({
"Age": [age],
"Sex": [encoder["Sex"].transform([sex])[0]],
"Job": [job],
"Housing": [encoder["Housing"].transform([housing])[0]],
"Saving accounts": [encoder["Saving accounts"].transform([saving_accounts])[0]],
"Checking account": [encoder["Checking account"].transform([checking_account])[0]],
"Credit amount": [credit_amount],
"Duration": [duration]
})
if st.button("Predict Risk"):
pred = model.predict(input_df)[0]
if pred == 1:
st.success("The predicted credit risk is: Good Credit Risk")
else:
st.error("The predicted credit risk is: Bad Credit Risk")