|
import streamlit as st |
|
import numpy as np |
|
import pickle |
|
|
|
|
|
with open('logistic_regression_model.pkl', 'rb') as file: |
|
model = pickle.load(file) |
|
|
|
|
|
with open('scaler.pkl', 'rb') as file: |
|
scaler = pickle.load(file) |
|
|
|
|
|
def predict_default(data): |
|
scaled_data = scaler.transform([data]) |
|
prediction = model.predict(scaled_data) |
|
return prediction[0] |
|
|
|
|
|
st.title("Credit Default Prediction") |
|
st.write("Enter the details to predict default payment next month") |
|
|
|
|
|
limit_balance = st.number_input('Limit Balance', min_value=0) |
|
sex = st.selectbox('Sex', options=[1, 2], format_func=lambda x: 'Male' if x == 1 else 'Female') |
|
education_level = st.selectbox('Education Level', options=[1, 2, 3, 4, 5, 6], format_func=lambda x: {1: 'graduate school', 2: 'university', 3: 'high school', 4: 'others', 5: 'unknown', 6: 'unknown'}.get(x, 'unknown')) |
|
marital_status = st.selectbox('Marital Status', options=[1, 2, 3], format_func=lambda x: {1: 'married', 2: 'single', 3: 'others'}.get(x, 'unknown')) |
|
age = st.number_input('Age', min_value=0) |
|
bill_amts = [st.number_input(f'Bill Amount {i+1}', min_value=0) for i in range(6)] |
|
pay_amts = [st.number_input(f'Previous Payment {i+1}', min_value=0) for i in range(6)] |
|
|
|
|
|
if st.button("Predict"): |
|
|
|
features = [limit_balance, sex, education_level, marital_status, age] + bill_amts + pay_amts |
|
prediction = predict_default(features) |
|
if prediction == 1: |
|
st.write("The client is likely to default next month.") |
|
else: |
|
st.write("The client is unlikely to default next month.") |
|
|