CristopherWVSU commited on
Commit
86ce41e
·
1 Parent(s): bfb1151

initial commit

Browse files
Files changed (5) hide show
  1. BankChurners.csv +0 -0
  2. app.py +61 -0
  3. bank_churn_model.pkl +3 -0
  4. main.ipynb +0 -0
  5. requirements.txt +5 -0
BankChurners.csv ADDED
The diff for this file is too large to render. See raw diff
 
app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import joblib
3
+ import numpy as np
4
+
5
+ # Load the trained model
6
+ model = joblib.load("bank_churn_model.pkl")
7
+
8
+ # Define categorical mappings
9
+ gender_map = {'Male': 0, 'Female': 1}
10
+ education_level_map = {'High School': 0, 'HS Graduate': 1, 'Uneducated': 2, 'Unknown': 3, 'College': 4, 'College Graduate': 5, 'Doctorate': 6}
11
+ marital_status_map = {'Married': 0, 'Single': 1, 'Unknown': 2, 'Divorced': 3}
12
+ card_category_map = {'Blue': 0, 'Gold': 1, 'Silver': 2, 'Platinum': 3}
13
+ income_category_map = {'Less than 40k': 0, '40-60k': 1, '60-80k': 2, '80-120k': 3, 'Unknown': 4}
14
+
15
+ # Streamlit UI
16
+ st.title("Customer Churn Prediction")
17
+
18
+ st.header("Enter Customer Details")
19
+
20
+ # User Inputs
21
+
22
+ customer_age = st.number_input("Enter Customer Age", min_value=1, max_value=100)
23
+ gender = st.selectbox("Gender", list(gender_map.keys()))
24
+ dependent_count = st.number_input("Number of Dependents (e.g children, spouse, or other family members) (0-5)", min_value=0, max_value=5)
25
+ education_level = st.selectbox("Education Level", list(education_level_map.keys()))
26
+ marital_status = st.selectbox("Marital Status", list(marital_status_map.keys()))
27
+ income_category = st.selectbox("Income Category", list(income_category_map.keys()))
28
+ card_category = st.selectbox("Card Category", list(card_category_map.keys()))
29
+ months_on_book = st.number_input("Enter Account Total of Months Active", min_value=0, max_value=100)
30
+ total_relationship_count = st.number_input("Total number of accounts or financial products the customer has with the bank ", min_value=0, max_value=100)
31
+ months_inactive_12_mon = st.number_input("Enter number of Years account is Inactive", min_value=0, max_value=100)
32
+ contacts_count_12_mon = st.number_input("Enter Account Total of Years Inactive", min_value=0, max_value=100)
33
+ credit_limit = st.number_input("Enter Maximum Credit Limit", min_value=1, max_value=100000000)
34
+ total_revolving_bal = st.number_input("Enter Total Revolving Balance in Account", min_value=0, max_value=100000000)
35
+ avg_open_to_buy = st.number_input("Enter Average amount of credit available to the customer on a revolving credit account", min_value=0, max_value=100000000)
36
+ total_amt_chng_q4_q1 = st.number_input("Enter change in total transaction amount from Quarter 4 to Quarter 1", min_value=0, max_value=100000000)
37
+ total_trans_amt = st.number_input("Enter Total Transaction Amount", min_value=0, max_value=100000000)
38
+ total_trans_ct = st.number_input("Enter Total Transaction Count", min_value=0, max_value=100000000)
39
+ total_ct_chng_q4_q1 = st.number_input("Enter change in total transaction Count from Quarter 4 to Quarter 1", min_value=0, max_value=100000000)
40
+ avg_utilization_ratio = st.number_input("Enter average ratio of credit card balance to credit limit over a period", min_value=0, max_value=100000000)
41
+
42
+
43
+ # Convert inputs to numerical values
44
+ gender_encoded = gender_map[gender]
45
+ education_encoded = education_level_map[education_level]
46
+ marital_status_encoded = marital_status_map[marital_status]
47
+ income_encoded = income_category_map[income_category]
48
+ card_encoded = card_category_map[card_category]
49
+
50
+
51
+
52
+ # Prepare data for prediction
53
+ user_input = np.array([[customer_age, gender_encoded, dependent_count, education_encoded, marital_status_encoded, income_encoded, card_encoded, months_on_book, total_relationship_count, months_inactive_12_mon, contacts_count_12_mon, credit_limit, total_revolving_bal, avg_open_to_buy, total_amt_chng_q4_q1 ,total_trans_amt, total_trans_ct, total_ct_chng_q4_q1, avg_utilization_ratio]])
54
+
55
+ # Predict button
56
+ if st.button("Predict Churn"):
57
+ prediction = model.predict(user_input)
58
+ if prediction[0] == 1:
59
+ st.error("🔴 This customer is likely to churn.")
60
+ else:
61
+ st.success("🟢 This customer is not likely to churn.")
bank_churn_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:01bba94b3ec1db720e23331e50707d1c4e8c0b5409660ddf5c7f5ee66e3e5a1d
3
+ size 1759
main.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ streamlit
2
+ numpy
3
+ pandas
4
+ matplotlib.pyplot
5
+ seaborn