predict_credit_card_default / predict_credit_card_default.py
nursakinahbadriah's picture
Upload 5 files
28b9906 verified
raw
history blame
5.62 kB
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
# Load the pre-trained model using pickle
with open('best_svm_model.pkl', 'rb') as file_1:
model = pickle.load(file_1)
# Create a Streamlit web app
def run():
st.title("Credit Card Default Prediction Dashboard")
# Add input fields for user input
st.header("User Input Features")
with st.form('predict player'):
st.title('Playernya aja')
# Input fields for each feature
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")
# Define mappings for education and marriage
education_mapping = {
"Graduate School": 1,
"University": 2,
"High School": 3,
"Others": 4
}
marriage_mapping = {
"Married": 1,
"Single": 2,
"Others": 3
}
# Create a DataFrame with user input data
user_input_data = pd.DataFrame({
"limit_balance": [limit_balance],
"sex": [1 if sex == "Male" else 2], # Map 'Male' to 1 and 'Female' to 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]
})
# Predict button
if submit:
# Make predictions using the loaded model
predicted_default = model.predict(user_input_data)
# Display the prediction result
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.")
#limit_balance,sex,education_level,marital_status,age,pay_1,pay_2,pay_3,pay_4,pay_5,pay_6,bill_amt_1,bill_amt_2,bill_amt_3,bill_amt_4,bill_amt_5,bill_amt_6,pay_amt_1,pay_amt_2,pay_amt_3,pay_amt_4,pay_amt_5,pay_amt_6,default_payment_next_month,Klasifikasi
#0,240000.0,2,2,1,41.0,1.0,-1.0,-1.0,-1.0,-1,-1,0.0,40529.0,3211.0,9795.0,11756.0,12522.0,40529.0,3211.0,9795.0,11756.0,12522.0,6199.0,0,Dewasa