Spaces:
Sleeping
Sleeping
import streamlit as st | |
import pandas as pd | |
import joblib | |
def run(): | |
st.markdown("<h1 style='text-align: center;'>Welcome to the Credit Default Prediction Model</h1>", unsafe_allow_html=True) | |
st.markdown("========================================================================================") | |
st.markdown("<h2 style='text-align: left;'>User Input Features</h2>", unsafe_allow_html=True) | |
def user_input(): | |
limit_balance = st.number_input('limit balance', min_value=10000, max_value=100000000, step=10000) | |
col1,col2= st.columns(2) | |
pay_1 = col1.slider('pay in september', min_value=-12, max_value=12, format="paid %d month") | |
pay_2 = col2.slider('pay in august', min_value=-12, max_value=12, format="paid %d month") | |
pay_3 = col1.slider('pay in july', min_value=-12, max_value=12, format="paid %d month") | |
pay_4 = col2.slider('pay in june', min_value=-12, max_value=12, format="paid %d month") | |
pay_5 = col1.slider('pay in may', min_value=-12, max_value=12, format="paid %d month") | |
pay_6 = col2.slider('pay in april', min_value=-12, max_value=12, format="paid %d month") | |
data = { | |
'limit_balance': limit_balance, | |
'pay_0': pay_1, | |
'pay_2': pay_2, | |
'pay_3': pay_3, | |
'pay_4': pay_4, | |
'pay_5': pay_5, | |
'pay_6': pay_6 | |
} | |
features = pd.DataFrame(data, index=[0]) | |
return features | |
input = user_input() | |
st.markdown("<h2 style='text-align: left;'>User Input Result</h2>", unsafe_allow_html=True) | |
st.table(input) | |
load_model = joblib.load("my_model.pkl") | |
if st.button("Predict", help='Click me!' ): | |
prediction = load_model.predict(input) | |
if prediction == 1: | |
prediction = 'Defaulted Payment' | |
else: | |
prediction = 'Not Defaulted' | |
st.markdown("<h4 style='text-align: center;'>Based on user input, the default model is predicted:</h4>", unsafe_allow_html=True) | |
st.markdown(f"<h1 style='text-align: center;'>{prediction}</h1>", unsafe_allow_html=True) | |