jarif commited on
Commit
fe0ce01
1 Parent(s): 034feeb

Upload 6 files

Browse files
Files changed (6) hide show
  1. app.py +74 -0
  2. label_encoder_gender.pkl +3 -0
  3. model.h5 +3 -0
  4. onehot_encoder_geo.pkl +3 -0
  5. requirements.txt +0 -0
  6. scaler.pkl +3 -0
app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import tensorflow as tf
4
+ from sklearn.preprocessing import StandardScaler, LabelEncoder, OneHotEncoder
5
+ import pandas as pd
6
+ import pickle
7
+
8
+ # Load the trained model
9
+ model = tf.keras.models.load_model('model.h5')
10
+
11
+ # Load the encoders and scaler
12
+ with open('label_encoder_gender.pkl', 'rb') as file:
13
+ label_encoder_gender = pickle.load(file)
14
+
15
+ with open('onehot_encoder_geo.pkl', 'rb') as file:
16
+ onehot_encoder_geo = pickle.load(file)
17
+
18
+ with open('scaler.pkl', 'rb') as file:
19
+ scaler = pickle.load(file)
20
+
21
+
22
+ ## Streamlit app
23
+ st.title('Customer Churn Prediction')
24
+
25
+ # User input
26
+ geography = st.selectbox('Geography', onehot_encoder_geo.categories_[0])
27
+ gender = st.selectbox('Gender', label_encoder_gender.classes_)
28
+ age = st.slider('Age', 18, 92)
29
+ balance = st.number_input('Balance')
30
+ credit_score = st.number_input('Credit Score')
31
+ estimated_salary = st.number_input('Estimated Salary')
32
+ tenure = st.slider('Tenure', 0, 10)
33
+ num_of_products = st.slider('Number of Products', 1, 4)
34
+ has_cr_card = st.selectbox('Has Credit Card', [0, 1])
35
+ is_active_member = st.selectbox('Is Active Member', [0, 1])
36
+
37
+ # Prepare the input data
38
+ input_data = pd.DataFrame({
39
+ 'CreditScore': [credit_score],
40
+ 'Gender': [label_encoder_gender.transform([gender])[0]],
41
+ 'Age': [age],
42
+ 'Tenure': [tenure],
43
+ 'Balance': [balance],
44
+ 'NumOfProducts': [num_of_products],
45
+ 'HasCrCard': [has_cr_card],
46
+ 'IsActiveMember': [is_active_member],
47
+ 'EstimatedSalary': [estimated_salary]
48
+ })
49
+
50
+ # One-hot encode 'Geography'
51
+ geo_encoded = onehot_encoder_geo.transform([[geography]]).toarray()
52
+
53
+ # Manually create column names for the one-hot encoded geography
54
+ geo_columns = [f'Geography_{category}' for category in onehot_encoder_geo.categories_[0]]
55
+
56
+ geo_encoded_df = pd.DataFrame(geo_encoded, columns=geo_columns)
57
+
58
+ # Combine one-hot encoded columns with input data
59
+ input_data = pd.concat([input_data.reset_index(drop=True), geo_encoded_df], axis=1)
60
+
61
+ # Scale the input data
62
+ input_data_scaled = scaler.transform(input_data)
63
+
64
+ # Predict churn
65
+ prediction = model.predict(input_data_scaled)
66
+ prediction_proba = prediction[0][0]
67
+
68
+ # Display the prediction result
69
+ st.write(f'Churn Probability: {prediction_proba:.2f}')
70
+
71
+ if prediction_proba > 0.5:
72
+ st.write('The customer is likely to churn.')
73
+ else:
74
+ st.write('The customer is not likely to churn.')
label_encoder_gender.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:360bd57973ec93035a912994862bffe697c19e212fddcd4f966fb030af35522a
3
+ size 258
model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9746b8918c0f16928c2797c35815fefd713d6f00c637b28dd8497e6f04fae782
3
+ size 62832
onehot_encoder_geo.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2f046f4d2e0236095bbec4afacb7bfa1bcde581696e52a72b8d4dc31fbf0b75a
3
+ size 597
requirements.txt ADDED
Binary file (2.48 kB). View file
 
scaler.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ac0cba24ccc97524d4e79423685898630de704289622df2aaa849e786b1bed44
3
+ size 992