File size: 3,899 Bytes
c1cacde
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8243175
c1cacde
 
 
 
 
 
8243175
c1cacde
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import numpy as np
import joblib

model = joblib.load("churn.joblib")

st.title("Credit Card Customer Churn Prediction")
def get_one_hot_encoding(value, categories):
    encoding = [False] * len(categories)
    if value in categories:
        encoding[categories.index(value)] = True
    return encoding

def prediction(model,arr):
    output = model.predict(arr)
    if output == 0:
        st.write("# Existing Customer")
    elif output==1:
        st.write("# Atrrited Customer")

gender_categories = ["Female", "Male"]
education_categories = ["College", "Doctorate","Graduate","High School","Post-Graduate","Uneducated","Unknown"]
marital_categories = ["Divorced", "Married","Single","Unknown"]
income_categories = ["0-40K", "120K Plus","40K-60K","60K-80K","80K-120K","Unknown"]
card_categories = ["Blue", "Gold","Platinum","Silver"]

with st.container():
    st.title("Enter details:")
    age = st.number_input("Enter age: ", min_value=1)
    dependent = st.number_input("Dependent Count: ", min_value=0)
    months = st.number_input("Months (on book): ", min_value = 0)
    relations = st.number_input("Total relationship count: ", min_value = 0)
    inactive = st.number_input("Inactive Months: ",min_value = 0)
    contacts_count = st.number_input("Total contacts (12 months): ",min_value = 0)
    revolving_bal = st.number_input("Revolving balance in ₹: ",min_value = 0)
    avg_open = st.number_input("Enter Average open to buy (in ₹):", min_value = 0)
    amt_change = st.number_input("Total amount change from Q1 to Q4:", min_value = 0)
    trans_amt = st.number_input("Total transaction amount :",min_value = 0)
    trans_count = st.number_input("Total transactions: ", min_value = 0)
    count_change = st.number_input("Total transactions count change from Q1 to Q4: ", min_value = 0)
    util_ratio = st.number_input("Average Utilization ratio: ", min_value = 0.0, max_value = 1.0, step=0.1)
    gender = st.selectbox("Enter Gender: ",("Female","Male"))
    education = st.selectbox("Education Level:",("College", "Doctorate","Graduate","High School","Post-Graduate","Uneducated","Unknown"))
    marital_stat = st.selectbox("Marital Status:",("Divorced", "Married","Single","Unknown"))
    income = st.selectbox("Income category:",("0-40K", "120K Plus","40K-60K","60K-80K","80K-120K","Unknown"))
    card = st.selectbox("Card Category:",("Blue", "Gold","Platinum","Silver"))
    

with st.container():
    arr = np.zeros((1, 36))
    
    arr[0, 0] = age
    arr[0, 1] = dependent
    arr[0, 2] = months
    arr[0, 3] = relations
    arr[0, 4] = inactive
    arr[0, 5] = contacts_count
    arr[0, 6] = revolving_bal
    arr[0, 7] = avg_open
    arr[0, 8] = amt_change
    arr[0, 9] = trans_amt
    arr[0, 10] = trans_count
    arr[0, 11] = count_change
    arr[0, 12] = util_ratio

    offset = 13
    
    # Gender
    gender_encoding = get_one_hot_encoding(gender, gender_categories)
    arr[0, offset:offset+len(gender_categories)] = gender_encoding
    offset += len(gender_categories)
    
    # Education
    education_encoding = get_one_hot_encoding(education, education_categories)
    arr[0, offset:offset+len(education_categories)] = education_encoding
    offset += len(education_categories)
    
    # Marital Status
    marital_encoding = get_one_hot_encoding(marital_stat, marital_categories)
    arr[0, offset:offset+len(marital_categories)] = marital_encoding
    offset += len(marital_categories)
    
    # Income
    income_encoding = get_one_hot_encoding(income, income_categories)
    arr[0, offset:offset+len(income_categories)] = income_encoding
    offset += len(income_categories)
    
    # Card
    card_encoding = get_one_hot_encoding(card, card_categories)
    arr[0, offset:offset+len(card_categories)] = card_encoding
    offset += len(card_categories)
    
    if st.button("Calculate"):
        prediction(model, arr)