Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import numpy as np
|
3 |
+
import pickle
|
4 |
+
|
5 |
+
# Load trained model
|
6 |
+
with open('logistic_regression_model.pkl', 'rb') as file:
|
7 |
+
model = pickle.load(file)
|
8 |
+
|
9 |
+
# Load scaler
|
10 |
+
with open('scaler.pkl', 'rb') as file:
|
11 |
+
scaler = pickle.load(file)
|
12 |
+
|
13 |
+
# Function to predict default payment next month
|
14 |
+
def predict_default(data):
|
15 |
+
scaled_data = scaler.transform([data])
|
16 |
+
prediction = model.predict(scaled_data)
|
17 |
+
return prediction[0]
|
18 |
+
|
19 |
+
# Creating a simple form
|
20 |
+
st.title("Credit Default Prediction")
|
21 |
+
st.write("Enter the details to predict default payment next month")
|
22 |
+
|
23 |
+
# Input fields
|
24 |
+
limit_balance = st.number_input('Limit Balance', min_value=0)
|
25 |
+
sex = st.selectbox('Sex', options=[1, 2], format_func=lambda x: 'Male' if x == 1 else 'Female')
|
26 |
+
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'))
|
27 |
+
marital_status = st.selectbox('Marital Status', options=[1, 2, 3], format_func=lambda x: {1: 'married', 2: 'single', 3: 'others'}.get(x, 'unknown'))
|
28 |
+
age = st.number_input('Age', min_value=0)
|
29 |
+
bill_amts = [st.number_input(f'Bill Amount {i+1}', min_value=0) for i in range(6)]
|
30 |
+
pay_amts = [st.number_input(f'Previous Payment {i+1}', min_value=0) for i in range(6)]
|
31 |
+
|
32 |
+
# Predict button
|
33 |
+
if st.button("Predict"):
|
34 |
+
# On predict button click, predict and display the result
|
35 |
+
features = [limit_balance, sex, education_level, marital_status, age] + bill_amts + pay_amts
|
36 |
+
prediction = predict_default(features)
|
37 |
+
if prediction == 1:
|
38 |
+
st.write("The client is likely to default next month.")
|
39 |
+
else:
|
40 |
+
st.write("The client is unlikely to default next month.")
|