File size: 2,099 Bytes
f715252
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import joblib
import streamlit as st
import pandas as pd

def main():
    st.title("Bank Customer Churn")

    credit_score = st.number_input("Credit Score")
    country = st.selectbox("Country", options=['France', 'Spain', 'Germany'])

    if country:
        st.success(country)

    gender = st.radio("Select Gender: ", ('Male', 'Female'))
    if (gender == 'Male'):
        st.success("Male")
    else:
        st.success("Female")
    
    age = st.number_input("Age")
    tenure = st.number_input("Tenure")
    balance = st.number_input("Balance")
    products_number = st.number_input("Products Number")
    credit_card = st.number_input("Credit Card")
    active_member = st.number_input("Active Member")
    estimated_salary = st.number_input("Estimated Salary")
    submit_button = st.button("Submit")

    if submit_button:
        # Process the form data
        process_form_data(credit_score, country, gender, age, tenure,
                          balance, products_number, credit_card, active_member, estimated_salary)

def process_form_data(credit_score, country, gender, age, tenure,
                          balance, products_number, credit_card, active_member, estimated_salary):


    encoders = joblib.load('encoders .joblib')
    model = joblib.load('rf_model.joblib')
    scaler = joblib.load('StandardScaler.joblib')


    dataDict = {'credit_score': credit_score, 'country': country, 'gender': gender, 'age': age, 'tenure':tenure,
                          'balance':balance, 'products_number': products_number, 'credit_card': credit_card,
                'active_member': active_member, 'estimated_salary': estimated_salary}

    df = pd.DataFrame([dataDict])

    decodedData = df.copy()
    for col in ['country', 'gender']:
        encoder = encoders[col]
        decodedData[col] = encoder.transform(decodedData[col])
    #
    decodedData = scaler.transform(decodedData)
    result = model.predict(decodedData)

    st.write(df)

    if result == 1:
        st.warning("Churn")
    if result == 0:
        st.success("Stay")



if __name__ == "__main__":
    main()