Spaces:
Sleeping
Sleeping
import streamlit as st | |
import pandas as pd | |
import joblib | |
# Load the bank_df_cleaned for reference | |
bank_df_cleaned = pd.read_csv('bank_df_cleaned.csv') | |
# Check if 'job' column exists | |
if 'job' not in bank_df_cleaned.columns: | |
st.error("The column 'job' does not exist in the DataFrame.") | |
else: | |
# Title and description | |
st.title("Banking Campaign Outcome Prediction App") | |
st.markdown(""" | |
Welcome to the **Banking Campaign Outcome Prediction App**! | |
This tool predicts whether a customer will respond positively to a banking campaign based on their demographic and transactional information. | |
Please input the required details below to get a prediction. | |
""") | |
# Load the saved model | |
model = joblib.load("HistGradientBoostingClassifier.joblib") | |
# Input features | |
st.header("Enter the details for prediction:") | |
job = st.selectbox('Job', bank_df_cleaned['job'].unique()) | |
marital = st.selectbox('Marital', bank_df_cleaned['marital'].unique()) | |
education = st.selectbox('Education', bank_df_cleaned['education'].unique()) | |
default = st.selectbox('Default', bank_df_cleaned['default'].unique()) | |
housing = st.selectbox('Housing Loan', bank_df_cleaned['housing'].unique()) | |
loan = st.selectbox('Personal Loan', bank_df_cleaned['loan'].unique()) | |
poutcome = st.selectbox('Previous Outcome', bank_df_cleaned['poutcome'].unique()) | |
log_campaign = st.slider('Log Campaign', float(bank_df_cleaned['log_campaign'].min()), float(bank_df_cleaned['log_campaign'].max())) | |
log_duration = st.slider('Log Duration', float(bank_df_cleaned['log_duration'].min()), float(bank_df_cleaned['log_duration'].max())) | |
log_age = st.slider('Log Age', float(bank_df_cleaned['log_age'].min()), float(bank_df_cleaned['log_age'].max())) | |
campaign_duration_interaction = log_campaign * log_duration | |
contact_is_cellular = st.selectbox('Contact is Cellular', [0, 1]) | |
total_loans = st.selectbox('Total Loans', [0, 1, 2]) | |
data = { | |
'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 | |
} | |
input_df = pd.DataFrame(data) | |
# Make prediction | |
prediction = model.predict(input_df) | |
outcome = "will subscribe to" if prediction[0] == 1 else "will not subscribe to" | |
st.success(f"Prediction: The customer {outcome} term deposit.") | |