-
Notifications
You must be signed in to change notification settings - Fork 1
/
front_end.py
120 lines (98 loc) · 2.21 KB
/
front_end.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
from contextlib import suppress
import streamlit as st
from PIL import Image
import pickle
import json
st.write("""
# Churn-Prediction-App
This app predicts if a customer will leave the bank or not.
"""
)
st.markdown("""
<style>
.big-font {
font-size:50px !important;
}
</style>
""", unsafe_allow_html=True)
@st.cache(suppress_st_warning=True, allow_output_mutation=True)
def load_model():
model = 'models/pipeline.bin'
with open(model, 'rb') as f_in:
pipeline = pickle.load(f_in)
return pipeline
pipeline = load_model()
image = Image.open('images/churn-fish.webp')
st.image(image, caption='')
gender = st.selectbox(
'Gender',
('Male', 'Female')
)
geography = st.selectbox(
'Geography',
('Spain', 'France', 'Germany')
)
age = st.slider(
'Age',
min_value = 18,
max_value = 100,
value = 35
)
has_cr_card = st.selectbox(
'HasCrCard',
('Yes', 'NO')
)
credit_score = st.slider(
'CreditScore',
min_value = 350,
max_value = 850,
value = 500
)
tenure = st.slider(
'Tenure',
min_value = 0,
max_value = 10,
value = 5
)
balance = st.slider(
'Balance',
min_value = 0,
max_value = 300000,
value = 150000
)
num_of_products = st.slider(
'NumOfProducts',
min_value = 0,
max_value = 30,
value = 2
)
estimated_salary = st.slider(
'EstimatedSalary',
min_value = 0,
max_value = 200000,
value = 50000
)
is_active_member = st.selectbox(
'IsActiveMember',
('Yes', 'No')
)
customer = {'CreditScore': float(credit_score),
'Geography': str(geography),
'Gender': str(gender),
'Age': int(age),
'Tenure': int(tenure),
'Balance': float(balance),
'NumOfProducts': int(num_of_products),
'HasCrCard': str(has_cr_card)=='Yes',
'IsActiveMember': str(is_active_member)=='Yes',
'EstimatedSalary': float(estimated_salary),
}
pred = pipeline.predict_proba(customer)[0,1]
pred = float(pred)
col1_pred, col2_pred = st.columns(2)
col1_pred.write("Probability of living the bank:")
col2_pred.write(f"{pred*100:.2f}%")
st.write("""
This project was done as a part of [the project-of-the-week
initiative at DataTalks.Club](https://github.com/DataTalksClub/project-of-the-week/blob/main/2022-08-14-frontend.md).
""")