Sonny4Sonnix commited on
Commit
57e7e31
·
verified ·
1 Parent(s): c3d56f7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -51
app.py CHANGED
@@ -7,54 +7,62 @@ import joblib
7
  # Load the saved model
8
  #model = joblib.load("HistGradientBoostingClassifier.joblib")
9
 
10
- # Load the trained model
11
- model = joblib.load("HistGradientBoostingClassifier.joblib")
12
-
13
- # Define categorical columns based on the dataset
14
- categorical_columns = ['job', 'marital', 'education', 'default', 'housing', 'loan', 'poutcome']
15
-
16
- # Sidebar for user input
17
- st.sidebar.header("Client Input Features")
18
- def user_input_features():
19
- job = st.sidebar.selectbox('Job', bank_df_cleaned['job'].unique())
20
- marital = st.sidebar.selectbox('Marital', bank_df_cleaned['marital'].unique())
21
- education = st.sidebar.selectbox('Education', bank_df_cleaned['education'].unique())
22
- default = st.sidebar.selectbox('Default', bank_df_cleaned['default'].unique())
23
- housing = st.sidebar.selectbox('Housing Loan', bank_df_cleaned['housing'].unique())
24
- loan = st.sidebar.selectbox('Personal Loan', bank_df_cleaned['loan'].unique())
25
- poutcome = st.sidebar.selectbox('Previous Outcome', bank_df_cleaned['poutcome'].unique())
26
- log_campaign = st.sidebar.slider('Log Campaign', float(bank_df_cleaned['log_campaign'].min()), float(bank_df_cleaned['log_campaign'].max()))
27
- log_duration = st.sidebar.slider('Log Duration', float(bank_df_cleaned['log_duration'].min()), float(bank_df_cleaned['log_duration'].max()))
28
- log_age = st.sidebar.slider('Log Age', float(bank_df_cleaned['log_age'].min()), float(bank_df_cleaned['log_age'].max()))
29
- campaign_duration_interaction = log_campaign * log_duration
30
- contact_is_cellular = st.sidebar.selectbox('Contact is Cellular', [0, 1])
31
- total_loans = st.sidebar.selectbox('Total Loans', [0, 1, 2])
32
-
33
- data = {
34
- 'job': job,
35
- 'marital': marital,
36
- 'education': education,
37
- 'default': default,
38
- 'housing': housing,
39
- 'loan': loan,
40
- 'poutcome': poutcome,
41
- 'log_campaign': log_campaign,
42
- 'log_duration': log_duration,
43
- 'log_age': log_age,
44
- 'campaign_duration_interaction': campaign_duration_interaction,
45
- 'contact_is_cellular': contact_is_cellular,
46
- 'total_loans': total_loans
47
- }
48
- return pd.DataFrame(data, index=[0])
49
-
50
- df = user_input_features()
51
-
52
-
53
- # Predict
54
- prediction = model.predict(df)
55
- prediction_proba = model.predict_proba(df)
56
-
57
- # Display result
58
- st.header("Term Deposit Subscription Prediction")
59
- st.write(f"Prediction: {'Yes' if prediction[0] == 1 else 'No'}")
60
- st.write(f"Prediction Probability: {prediction_proba[0]}")
 
 
 
 
 
 
 
 
 
7
  # Load the saved model
8
  #model = joblib.load("HistGradientBoostingClassifier.joblib")
9
 
10
+ import streamlit as st
11
+ import joblib
12
+ import pandas as pd
13
+
14
+ # Load the model
15
+ model = joblib.load('HistGradientBoostingClassifier.joblib')
16
+
17
+ # Title of the app
18
+ st.title('Bank Term Deposit Prediction App')
19
+
20
+ # Input fields for user data
21
+ age = st.number_input('Age', min_value=18, max_value=100, value=30)
22
+ job = st.selectbox('Job', ['admin.', 'blue-collar', 'entrepreneur', 'housemaid', 'management', 'retired', 'self-employed', 'services', 'student', 'technician', 'unemployed', 'unknown'])
23
+ marital = st.selectbox('Marital Status', ['divorced', 'married', 'single', 'unknown'])
24
+ education = st.selectbox('Education', ['primary', 'secondary', 'tertiary', 'unknown'])
25
+ default = st.selectbox('Default', ['no', 'yes'])
26
+ balance = st.number_input('Balance', value=0)
27
+ housing = st.selectbox('Housing Loan', ['no', 'yes'])
28
+ loan = st.selectbox('Personal Loan', ['no', 'yes'])
29
+ contact = st.selectbox('Contact Communication Type', ['cellular', 'telephone', 'unknown'])
30
+ day = st.number_input('Last Contact Day', min_value=1, max_value=31, value=15)
31
+ month = st.selectbox('Last Contact Month', ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'])
32
+ duration = st.number_input('Last Contact Duration', value=0)
33
+ campaign = st.number_input('Number of Contacts Performed', value=1)
34
+ pdays = st.number_input('Number of Days Passed After Last Contact', value=-1)
35
+ previous = st.number_input('Number of Contacts Performed Before', value=0)
36
+ poutcome = st.selectbox('Outcome of Previous Marketing Campaign', ['failure', 'nonexistent', 'success'])
37
+
38
+ # Create a dataframe from user input
39
+ data = {
40
+ 'age': [age],
41
+ 'job': [job],
42
+ 'marital': [marital],
43
+ 'education': [education],
44
+ 'default': [default],
45
+ 'balance': [balance],
46
+ 'housing': [housing],
47
+ 'loan': [loan],
48
+ 'contact': [contact],
49
+ 'day': [day],
50
+ 'month': [month],
51
+ 'duration': [duration],
52
+ 'campaign': [campaign],
53
+ 'pdays': [pdays],
54
+ 'previous': [previous],
55
+ 'poutcome': [poutcome]
56
+ }
57
+
58
+ input_df = pd.DataFrame(data)
59
+
60
+ # Predict the outcome
61
+ if st.button('Predict'):
62
+ prediction = model.predict(input_df)
63
+ if prediction[0] == 1:
64
+ st.success('The client is likely to subscribe for a term deposit.')
65
+ else:
66
+ st.error('The client is unlikely to subscribe for a term deposit.')
67
+
68
+