-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
38 lines (31 loc) · 1.54 KB
/
Copy pathapp.py
File metadata and controls
38 lines (31 loc) · 1.54 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
import streamlit as st
import pandas as pd
import joblib
model = joblib.load('extra_tree_credit_model.pkl')
encoders = {col: joblib.load(f'{col}_encoder.pkl') for col in ['Sex', 'Housing', 'Saving accounts', 'Checking account']}
st.title('Credit Risk Predication 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 = 80, value = 30)
sex = st.selectbox('Sex', ['male', 'female'])
job = st.number_input('Job (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'])
credit_amount = st.number_input('Credit Amount', min_value=0, value = 100)
duration = st.number_input('Duration (months)', min_value=1, value=12)
input_df = pd.DataFrame({
'Age': [age],
'Sex': [1 if sex == 'male' else 0],
'Job': [job],
'Housing': [encoders['Housing'].transform([housing])[0]],
'Saving accounts': [encoders['Saving accounts'].transform([saving_accounts])[0]],
'Checking account': [encoders['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**')
else:
st.error('The predicted credit risk is: **BAD**')