7sugiwa's picture
Upload app.py
8330464
import streamlit as st
import numpy as np
import pickle
# Load trained model
with open('logistic_regression_model.pkl', 'rb') as file:
model = pickle.load(file)
# Load scaler
with open('scaler.pkl', 'rb') as file:
scaler = pickle.load(file)
# Function to predict default payment next month
def predict_default(data):
scaled_data = scaler.transform([data])
prediction = model.predict(scaled_data)
return prediction[0]
# Creating a simple form
st.title("Credit Default Prediction")
st.write("Enter the details to predict default payment next month")
# Input fields
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)]
# Predict button
if st.button("Predict"):
# On predict button click, predict and display the result
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.")