banking_app / app.py
Sonny4Sonnix's picture
Update app.py
08d25b6 verified
# Import necessary libraries
import streamlit as st
import pandas as pd
import joblib
# Load the model
model = joblib.load('HistGradientBoostingClassifier.joblib')
# Load and preprocess data (example with dummy data)
def load_data():
data = {
'job': ['housemaid', 'services', 'services', 'admin.', 'services'],
'marital': ['married', 'married', 'married', 'married', 'married'],
'education': ['basic.4y', 'high.school', 'high.school', 'basic.6y', 'high.school'],
'default': ['no', 'unknown', 'no', 'no', 'no'],
'housing': ['no', 'no', 'yes', 'no', 'no'],
'loan': ['no', 'no', 'no', 'no', 'yes'],
'poutcome': ['nonexistent', 'nonexistent', 'nonexistent', 'nonexistent', 'nonexistent'],
'y': ['no', 'no', 'no', 'no', 'no'],
'log_campaign': [0.693147, 0.693147, 0.693147, 0.693147, 0.693147],
'log_duration': [5.568345, 5.010635, 5.424950, 5.023881, 5.730100],
'log_age': [4.043051, 4.060443, 3.637586, 3.713572, 4.043051],
'campaign_duration_interaction': [3.859682, 3.473108, 3.760289, 3.482289, 3.971803],
'contact_is_cellular': [0, 0, 0, 0, 0],
'total_loans': [0, 0, 1, 0, 1],
}
return pd.DataFrame(data)
# Streamlit app
st.title('Term Deposit Subscription Predictor')
st.subheader('Enter client details:')
job = st.selectbox('Job', ['admin.', 'blue-collar', 'entrepreneur', 'housemaid', 'management', 'retired', 'self-employed', 'services', 'student', 'technician', 'unemployed', 'unknown'])
marital = st.selectbox('Marital Status', ['single', 'married', 'divorced'])
education = st.selectbox('Education', ['basic.4y', 'basic.6y', 'basic.9y', 'high.school', 'professional.course', 'university.degree', 'unknown'])
default = st.selectbox('Default', ['no', 'yes', 'unknown'])
housing = st.selectbox('Housing', ['no', 'yes', 'unknown'])
loan = st.selectbox('Loan', ['no', 'yes', 'unknown'])
y = st.selectbox('y', ['no', 'yes'])
poutcome = st.selectbox('Poutcome', ['nonexistent', 'failure', 'success'])
log_campaign = st.number_input('Log Campaign', min_value=0.0, value=0.693147)
log_duration = st.number_input('Log Duration', min_value=0.0, value=5.568345)
log_age = st.number_input('Log Age', min_value=0.0, value=4.043051)
campaign_duration_interaction = st.number_input('Campaign Duration Interaction', min_value=0.0, value=3.859682)
contact_is_cellular = st.selectbox('Contact is Cellular', [0, 1])
total_loans = st.number_input('Total Loans', min_value=0, value=0)
# Prepare input data
input_data = pd.DataFrame({
'job': [job], 'marital': [marital], 'education': [education], 'default': [default], 'housing': [housing], 'loan': [loan],
'poutcome': [poutcome], 'log_campaign': [log_campaign], 'log_duration': [log_duration], 'log_age': [log_age],
'campaign_duration_interaction': [campaign_duration_interaction], 'contact_is_cellular': [contact_is_cellular], 'total_loans': [total_loans]
})
# Convert categorical variables to dummy/indicator variables
#input_data = pd.get_dummies(input_data, drop_first=True)
# Add a predict button
if st.button('Predict'):
# Make prediction
prediction = model.predict(input_data)[0]
# Display result
if prediction == 1:
st.success('The client will subscribe to a term deposit.')
else:
st.warning('The client will not subscribe to a term deposit.')