Andreean commited on
Commit
c94d5f8
·
1 Parent(s): dc24457

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -0
app.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import tensorflow as tf
3
+ from tensorflow import keras
4
+ import pandas as pd
5
+ import numpy as np
6
+ import pickle
7
+ from tensorflow.keras.models import load_model
8
+ from PIL import Image
9
+
10
+ st.set_page_config(page_title = 'Customer Churn Prediction',
11
+ initial_sidebar_state = "expanded",
12
+ menu_items = {
13
+ 'About' : 'Milestone 1 Customer Churn Predicton '
14
+ })
15
+
16
+ image = Image.open('indihome.jpg')
17
+
18
+ # load model
19
+ class columnDropperTransformer():
20
+ def __init__(self, columns):
21
+ self.columns = columns
22
+
23
+ def transform(self, X, y=None):
24
+ return X.drop(self.columns, axis=1)
25
+
26
+ def fit(self, X, y=None):
27
+ return self
28
+
29
+ pickles = open('preprocessings.pkl', 'rb')
30
+ preprocessing = pickle.load(pickles)
31
+ saved_model=load_model('Model.h5')
32
+
33
+ def predict(inputs):
34
+ df = pd.DataFrame(inputs, index=[0])
35
+ df = preprocessing.transform(df)
36
+ y_pred = saved_model.predict(df)
37
+ y_pred = np.where(y_pred < 0.5, 0, 1).squeeze()
38
+ print(y_pred)
39
+ return y_pred.item()
40
+
41
+ columns = ['SeniorCitizen', 'Partner', 'tenure', 'MultipleLines', 'InternetService', 'OnlineSecurity', 'OnlineBackup',
42
+ 'DeviceProtection', 'TechSupport', 'Contract', 'MonthlyCharges', 'TotalCharges']
43
+ label = ['Not Churn', 'Churn']
44
+
45
+ st.title("Customer Churn Prediction")
46
+ st.image(image)
47
+
48
+
49
+ SeniorCitizen = st.selectbox("Senior Citizen", ['Yes', 'No'])
50
+ Partner = st.selectbox("Marriage Status", ['Married', 'Not Married'])
51
+ tenure = st.slider("Tenure Length", min_value=0.0, max_value=72.0, value=24.0, step=1.0, help='Tenure Length Default 24 Months')
52
+ MultipleLines = st.selectbox("Multiple Lines", ['Yes', 'No'])
53
+ InternetService = st.selectbox("Which internet service do you use?", ['DSL', 'Fiber optic', 'No'])
54
+ OnlineSecurity = st.selectbox("Do you have online security?", ['No', 'Yes', 'No internet service'])
55
+ OnlineBackup = st.selectbox("Do you have online backup?", ['No', 'Yes', 'No internet service'])
56
+ DeviceProtection = st.selectbox("Do you have device protection?", ['No', 'Yes', 'No internet service'])
57
+ TechSupport = st.selectbox("Do you have Tech Support?", ['No', 'Yes', 'No internet service'])
58
+ Contract = st.selectbox("Which contract do you use?", ['Month-to-month', 'One year', 'Two year'])
59
+ MonthlyCharges = st.number_input("Monthly Charges", min_value=19.0, max_value=119.0, value=75.0, step=0.1, help='Customers Monthly Charges Default is $75')
60
+ TotalCharges = st.number_input("Total Charges", min_value=19.0, max_value=8685.0, value=500.0, step=0.1, help='Customers Total Charges Default is $500')
61
+
62
+ #inference
63
+ new_data = [SeniorCitizen, Partner, tenure,
64
+ MultipleLines, InternetService, OnlineSecurity, OnlineBackup,
65
+ DeviceProtection, TechSupport,
66
+ Contract, MonthlyCharges, TotalCharges]
67
+ new_data = pd.DataFrame([new_data], columns = columns)
68
+ new_data = preprocessing.transform(new_data).tolist()
69
+ res = saved_model.predict(new_data)
70
+
71
+ res = 0 if res < 0.5 else 1
72
+
73
+ press = st.button('Predict')
74
+ if press:
75
+ st.title(label[res])