DataWizard9742 commited on
Commit
fad1f48
·
verified ·
1 Parent(s): 1007c03

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -0
app.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # importing the libraries
2
+ import pickle
3
+ import streamlit as st
4
+ import pandas as pd
5
+
6
+ # calling our pickle file
7
+ model = pickle.load(open("model.pkl", "rb"))
8
+
9
+ # creating a title for website
10
+ st.title("Customer Churn Prediction for Banks")
11
+
12
+ min_max_values = {
13
+ 'credit_score': {'min': 350, 'max': 850},
14
+ 'age': {'min': 18, 'max': 92},
15
+ 'tenure': {'min': 0, 'max': 20},
16
+ 'balance': {'min': 0, 'max': 250000},
17
+ 'num_of_products': {'min': 1, 'max': 4},
18
+ 'estimated_salary': {'min': 10000, 'max': 200000}
19
+ }
20
+ def min_max_scale(value, feature_name):
21
+ min_val = min_max_values[feature_name]['min']
22
+ max_val = min_max_values[feature_name]['max']
23
+ return (value - min_val) / (max_val - min_val)
24
+
25
+ credit_score = min_max_scale(
26
+ st.number_input("Credit Score:", min_value=350, max_value=850, help="Enter a value between 350 and 850"),
27
+ 'credit_score'
28
+ )
29
+
30
+ gender = st.number_input("Gender (1 for Male, 0 for Female):", min_value=0, max_value=1)
31
+ age = min_max_scale(
32
+ st.number_input("Age:", min_value=18, max_value=92),
33
+ 'age'
34
+ )
35
+ tenure = min_max_scale(
36
+ st.number_input("Tenure (years):", min_value=0, max_value=20),
37
+ 'tenure'
38
+ )
39
+ balance = min_max_scale(
40
+ st.number_input("Account Balance:", help="Enter your account balance"),
41
+ 'balance'
42
+ )
43
+ num_of_products = min_max_scale(
44
+ st.number_input("Number of Products:", min_value=1, max_value=4),
45
+ 'num_of_products'
46
+ )
47
+ has_credit_card = st.number_input("Do you have a Credit Card? (1 for Yes, 0 for No)")
48
+ is_active_member = st.number_input("Are you an Active Member? (1 for Yes, 0 for No)")
49
+ estimated_salary = min_max_scale(
50
+ st.number_input("Estimated Salary:", help="Enter your estimated annual salary"),
51
+ 'estimated_salary'
52
+ )
53
+
54
+ country_options = {"France": 1, "Spain": 2, "Germany": 3}
55
+ country = st.radio("Choose your country:", list(country_options.keys()))
56
+ country_code = country_options[country]
57
+
58
+ user_input_scaled = pd.DataFrame([[
59
+ credit_score, gender, age, tenure, balance, num_of_products,
60
+ has_credit_card, is_active_member, estimated_salary, country_code
61
+ ]])
62
+
63
+ if st.button("Predict Churn"):
64
+ prediction = model.predict(user_input_scaled)[0]
65
+ message = "The customer is most likely to churn." if prediction == 1 else "The customer is not likely to churn."
66
+ st.write(message)