Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pandas as pd | |
| import pickle | |
| def get_input_data(): | |
| gender_map = {"Male": 1, "Female": 2} | |
| edu_map = {"Graduate School": 1, "University": 2, "High School": 3, "Others": 4} | |
| marital_map = {"Married": 1, "Single": 2, "Others": 3} | |
| pay_option_map = { | |
| "-2: Unused": -2, | |
| "-1: Pay duly": -1, | |
| "0: Revolving credit": 0, | |
| "1: One month late payment": 1, | |
| "2: Two months late payment": 2, | |
| "3: Three months late payment": 3, | |
| "4: Four months late payment": 4, | |
| "5: Five months late payment": 5, | |
| "6: Six months late payment": 6, | |
| "7: Seven months late payment": 7, | |
| "8: Eight months late payment": 8, | |
| "9: Nine months or above late payment": 9 | |
| } | |
| limit_balance = st.number_input(label="Input the account's limit balance", min_value=0.0) | |
| gender = gender_map[st.selectbox(label="Gender", options=list(gender_map.keys()))] | |
| education = edu_map[st.selectbox(label="Education level", options=list(edu_map.keys()))] | |
| marital = marital_map[st.selectbox(label="Marital status", options=list(marital_map.keys()))] | |
| age = st.number_input(label="Age", min_value=18, format='%d') | |
| pay_status, bill_amt, paid_amt = {}, {}, {} | |
| months = ["September", "August", "July", "June", "May", "April"] | |
| for month in months: | |
| pay_status[month] = pay_option_map[st.selectbox(label=f"Repayment status in {month}", options=list(pay_option_map.keys()))] | |
| bill_amt[month] = st.number_input(label=f"Bill amount in {month}") | |
| paid_amt[month] = st.number_input(label=f"Paid amount in {month}", min_value=0.0) | |
| return pd.DataFrame({ | |
| "limit_balance": [limit_balance], | |
| "gender": [gender], | |
| "education_level": [education], | |
| "marital_status": [marital], | |
| "age": [age], | |
| **{f"pay_{i}": [pay_status[month]] for i, month in enumerate(months, start=1)}, | |
| **{f"bill_amt_{i}": [bill_amt[month]] for i, month in enumerate(months, start=1)}, | |
| **{f"pay_amt_{i}": [paid_amt[month]] for i, month in enumerate(months, start=1)} | |
| }) | |
| def display_prediction(data_inf): | |
| with open("model_svm.pkl", 'rb') as file: | |
| model = pickle.load(file) | |
| y_pred_inf = model.predict(data_inf) | |
| if y_pred_inf == 0: | |
| st.write("Not Default Payment") | |
| else: | |
| st.write("Default Payment") | |
| def run(): | |
| st.title("Predict the payment type") | |
| data_inf = get_input_data() | |
| st.header("Table Input") | |
| st.table(data_inf) | |
| if st.button(label="Predict"): | |
| display_prediction(data_inf) | |