|
import streamlit as st |
|
import pandas as pd |
|
import pickle |
|
import streamlit as st |
|
|
|
import pandas as pd |
|
import numpy as np |
|
import pickle |
|
import json |
|
|
|
|
|
with open('best_svm_model.pkl', 'rb') as file_1: |
|
model = pickle.load(file_1) |
|
|
|
|
|
def run(): |
|
st.title("Credit Card Default Prediction Dashboard") |
|
|
|
|
|
st.header("User Input Features") |
|
|
|
with st.form('predict player'): |
|
st.title('Playernya aja') |
|
|
|
|
|
limit_balance = st.slider("LIMIT_BAL (Amount of Credit in NT dollars)", 0, 1000000, 50000) |
|
sex = st.radio("SEX (Gender)", ["Male", "Female"]) |
|
education = st.radio("EDUCATION (Education Level)", ["Graduate School", "University", "High School", "Others"]) |
|
marriage = st.radio("MARRIAGE (Marital Status)", ["Married", "Single", "Others"]) |
|
age = st.slider("AGE (Age in years)", 20, 80, 30) |
|
st.write('Payment Status') |
|
st.write("-1 : Sudah Dibayar Sebelum H-1") |
|
st.write("-2 : Sudah Dibayar Sebelum H-2") |
|
st.write("0 : Dibayar Tepat Waktu") |
|
st.write("2 : Telat Pembayaran 2 Bulan") |
|
st.write("3 : Telat Pembayaran 3 Bulan") |
|
st.write("4 : Telat Pembayaran 4 Bulan") |
|
st.write("5 : Telat Pembayaran 5 Bulan") |
|
st.write("6 : Telat Pembayaran 6 Bulan") |
|
pay_status_sept = st.slider("PAY_0 (Repayment status in September, 2005)", -2, 8, 0) |
|
pay_status_aug = st.slider("PAY_2 (Repayment status in August, 2005)", -2, 8, 0) |
|
pay_status_jul = st.slider("PAY_3 (Repayment status in July, 2005)", -2, 8, 0) |
|
pay_status_jun = st.slider("PAY_4 (Repayment status in June, 2005)", -2, 8, 0) |
|
pay_status_may = st.slider("PAY_5 (Repayment status in May, 2005)", -2, 8, 0) |
|
pay_status_apr = st.slider("PAY_6 (Repayment status in April, 2005)", -2, 8, 0) |
|
bill_amt_sept = st.slider("BILL_AMT1 (Bill statement in September, 2005 - NT dollar)", 0, 1000000, 5000) |
|
bill_amt_aug = st.slider("BILL_AMT2 (Bill statement in August, 2005 - NT dollar)", 0, 1000000, 5000) |
|
bill_amt_jul = st.slider("BILL_AMT3 (Bill statement in July, 2005 - NT dollar)", 0, 1000000, 5000) |
|
bill_amt_jun = st.slider("BILL_AMT4 (Bill statement in June, 2005 - NT dollar)", 0, 1000000, 5000) |
|
bill_amt_may = st.slider("BILL_AMT5 (Bill statement in May, 2005 - NT dollar)", 0, 1000000, 5000) |
|
bill_amt_apr = st.slider("BILL_AMT6 (Bill statement in April, 2005 - NT dollar)", 0, 1000000, 5000) |
|
pay_amt_sept = st.slider("PAY_AMT1 (Previous payment in September, 2005 - NT dollar)", 0, 100000, 500) |
|
pay_amt_aug = st.slider("PAY_AMT2 (Previous payment in August, 2005 - NT dollar)", 0, 100000, 500) |
|
pay_amt_jul = st.slider("PAY_AMT3 (Previous payment in July, 2005 - NT dollar)", 0, 100000, 500) |
|
pay_amt_jun = st.slider("PAY_AMT4 (Previous payment in June, 2005 - NT dollar)", 0, 100000, 500) |
|
pay_amt_may = st.slider("PAY_AMT5 (Previous payment in May, 2005 - NT dollar)", 0, 100000, 500) |
|
pay_amt_apr = st.slider("PAY_AMT6 (Previous payment in April, 2005 - NT dollar)", 0, 100000, 500) |
|
|
|
submit = st.form_submit_button("Predict Player Rating") |
|
|
|
|
|
education_mapping = { |
|
"Graduate School": 1, |
|
"University": 2, |
|
"High School": 3, |
|
"Others": 4 |
|
} |
|
|
|
marriage_mapping = { |
|
"Married": 1, |
|
"Single": 2, |
|
"Others": 3 |
|
} |
|
|
|
|
|
user_input_data = pd.DataFrame({ |
|
"limit_balance": [limit_balance], |
|
"sex": [1 if sex == "Male" else 2], |
|
"education_level": [education_mapping[education]], |
|
"marital_status": [marriage_mapping[marriage]], |
|
"age": [age], |
|
"pay_1": [pay_status_sept], |
|
"pay_2": [pay_status_aug], |
|
"pay_3": [pay_status_jul], |
|
"pay_4": [pay_status_jun], |
|
"pay_5": [pay_status_may], |
|
"pay_6": [pay_status_apr], |
|
"bill_amt_1": [bill_amt_sept], |
|
"bill_amt_2": [bill_amt_aug], |
|
"bill_amt_3": [bill_amt_jul], |
|
"bill_amt_4": [bill_amt_jun], |
|
"bill_amt_5": [bill_amt_may], |
|
"bill_amt_6": [bill_amt_apr], |
|
"pay_amt_1": [pay_amt_sept], |
|
"pay_amt_2": [pay_amt_aug], |
|
"pay_amt_3": [pay_amt_jul], |
|
"pay_amt_4": [pay_amt_jun], |
|
"pay_amt_5": [pay_amt_may], |
|
"pay_amt_6": [pay_amt_apr] |
|
}) |
|
|
|
|
|
if submit: |
|
|
|
predicted_default = model.predict(user_input_data) |
|
|
|
|
|
st.subheader("Prediction Result") |
|
if predicted_default[0] == 1: |
|
st.write("The model predicts that the client may default on their credit card payment.") |
|
else: |
|
st.write("The model predicts that the client is unlikely to default on their credit card payment.") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|