DataWizard9742 commited on
Commit
3e96f2e
1 Parent(s): ffb8389

Create app.py

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