File size: 2,317 Bytes
3e96f2e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# importing the libraries
import pickle
import streamlit as st
import pandas as pd
import sklearn
import numpy

# calling our pickle file
model = pickle.load(open("model-3.pkl", "rb"))

# creating a title for website
st.title("Customer Churn Prediction for Banks")

min_max_values = {
    'credit_score': {'min': 350, 'max': 850},
    'age': {'min': 18, 'max': 92},
    'tenure': {'min': 0, 'max': 20},
    'balance': {'min': 0, 'max': 250000},
    'num_of_products': {'min': 1, 'max': 4},
    'estimated_salary': {'min': 10000, 'max': 200000}
}
def min_max_scale(value, feature_name):
    min_val = min_max_values[feature_name]['min']
    max_val = min_max_values[feature_name]['max']
    return (value - min_val) / (max_val - min_val)

credit_score = min_max_scale(
    st.number_input("Credit Score:", min_value=350, max_value=850, help="Enter a value between 350 and 850"),
    'credit_score'
)

gender = st.number_input("Gender (1 for Male, 0 for Female):", min_value=0, max_value=1)
age = min_max_scale(
    st.number_input("Age:", min_value=18, max_value=92),
    'age'
)
tenure = min_max_scale(
    st.number_input("Tenure (years):", min_value=0, max_value=20),
    'tenure'
)
balance = min_max_scale(
    st.number_input("Account Balance:", help="Enter your account balance"),
    'balance'
)
num_of_products = min_max_scale(
    st.number_input("Number of Products:", min_value=1, max_value=4),
    'num_of_products'
)
has_credit_card = st.number_input("Do you have a Credit Card? (1 for Yes, 0 for No)")
is_active_member = st.number_input("Are you an Active Member? (1 for Yes, 0 for No)")
estimated_salary = min_max_scale(
    st.number_input("Estimated Salary:", help="Enter your estimated annual salary"),
    'estimated_salary'
)

country_options = {"France": 1, "Spain": 2, "Germany": 3}
country = st.radio("Choose your country:", list(country_options.keys()))
country_code = country_options[country]

user_input_scaled = pd.DataFrame([[
    credit_score, gender, age, tenure, balance, num_of_products,
    has_credit_card, is_active_member, estimated_salary, country_code
]])

if st.button("Predict Churn"):
    prediction = model.predict(user_input_scaled)[0]
    message = "The customer is most likely to churn." if prediction == 1 else "The customer is not likely to churn."
    st.write(message)