aaronayitey commited on
Commit
fc4d334
1 Parent(s): a87966b

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +79 -0
  2. rf_model.joblib +3 -0
app.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import joblib
3
+ import pandas as pd
4
+ import numpy as np
5
+
6
+ # Define prediction function
7
+ def make_prediction(
8
+ gender, SeniorCitizen, Partner, Dependents, tenure, PhoneService,
9
+ MultipleLines, InternetService, OnlineSecurity, OnlineBackup,
10
+ DeviceProtection, TechSupport, StreamingTV, StreamingMovies,
11
+ Contract, PaperlessBilling, PaymentMethod,
12
+ MonthlyCharges, TotalCharges):
13
+
14
+
15
+ # Make a dataframe from input data
16
+ input_data = pd.DataFrame({
17
+ 'gender': [gender], 'SeniorCitizen': [SeniorCitizen], 'Partner': [Partner],
18
+ 'Dependents': [Dependents], 'tenure': [tenure], 'PhoneService': [PhoneService],
19
+ 'MultipleLines': [MultipleLines], 'InternetService': [InternetService],
20
+ 'OnlineSecurity': [OnlineSecurity], 'OnlineBackup': [OnlineBackup],
21
+ 'DeviceProtection': [DeviceProtection], 'TechSupport': [TechSupport],
22
+ 'StreamingTV': [StreamingTV], 'StreamingMovies': [StreamingMovies],
23
+ 'Contract': [Contract], 'PaperlessBilling': [PaperlessBilling],
24
+ 'PaymentMethod': [PaymentMethod], 'MonthlyCharges': [MonthlyCharges],
25
+ 'TotalCharges': [TotalCharges]
26
+ })
27
+
28
+ # Load already saved pipeline and make predictions
29
+ with open("preprocessor.joblib", "rb") as p:
30
+ preprocessor = joblib.load(p)
31
+ input_data = preprocessor.transform(input_data)
32
+ # You may need to update this part to drop the relevant columns for your model
33
+ input_data = input_data.drop(['encode__PaperlessBilling_No', 'encode__MultipleLines_No', 'encode__InternetService_Fiber optic', 'encode__StreamingMovies_No internet service', 'encode__InternetService_No', 'encode__OnlineBackup_No internet service', 'encode__StreamingTV_No internet service'], axis=1)
34
+
35
+ # Load already saved pipeline and make predictions
36
+ with open("rf_model.joblib", "rb") as f:
37
+ model = joblib.load(f)
38
+ predt = model.predict(input_data)
39
+
40
+
41
+ # Return prediction
42
+ if np.any(predt == 1):
43
+ return 'Customer Will Churn'
44
+ else:
45
+ return 'Customer Will Not Churn'
46
+
47
+
48
+ # Create the input components for Gradio with labels
49
+ gender_input = gr.Dropdown(choices=['Female', 'Male'], label='Select gender')
50
+ SeniorCitizen_input = gr.Dropdown(choices=['Yes', 'No'], label='Is the customer a senior citizen?')
51
+ Partner_input = gr.Dropdown(choices=['Yes', 'No'], label='Has the customer a partner?')
52
+ Dependents_input = gr.Dropdown(choices=['Yes', 'No'], label='Does the customer have dependents?')
53
+ tenure_input = gr.Number(label='Number of months the customer has stayed with the company')
54
+ PhoneService_input = gr.Dropdown(choices=['Yes', 'No'], label='Does the customer have phone service?')
55
+ MultipleLines_input = gr.Dropdown(choices=['No phone service', 'No', 'Yes'], label='Does the customer have multiple phone lines?')
56
+ InternetService_input = gr.Dropdown(choices=['DSL', 'Fiber optic', 'No'], label='Type of Internet service')
57
+ OnlineSecurity_input = gr.Dropdown(choices=['No', 'Yes', 'No internet service'], label='Does the customer have online security?')
58
+ OnlineBackup_input = gr.Dropdown(choices=['Yes', 'No', 'No internet service'], label='Does the customer have online backup?')
59
+ DeviceProtection_input = gr.Dropdown(choices=['No', 'Yes', 'No internet service'], label='Does the customer have device protection?')
60
+ TechSupport_input = gr.Dropdown(choices=['No', 'Yes', 'No internet service'], label='Does the customer have tech support?')
61
+ StreamingTV_input = gr.Dropdown(choices=['No', 'Yes', 'No internet service'], label='Does the customer have streaming TV?')
62
+ StreamingMovies_input = gr.Dropdown(choices=['No', 'Yes', 'No internet service'], label='Does the customer have streaming movies?')
63
+ Contract_input = gr.Dropdown(choices=['Month-to-month', 'One year', 'Two year'], label='Type of contract')
64
+ PaperlessBilling_input = gr.Dropdown(choices=['Yes', 'No'], label='Is the customer using paperless billing?')
65
+ PaymentMethod_input = gr.Dropdown(choices=['Electronic check', 'Mailed check', 'Bank transfer (automatic)', 'Credit card (automatic)'], label='Payment method')
66
+ MonthlyCharges_input = gr.Number(label='Monthly charges')
67
+ TotalCharges_input = gr.Number(label='Total charges')
68
+
69
+ output = gr.Textbox(label='Prediction')
70
+
71
+ # Set the title of the Gradio app
72
+ app = gr.Interface(fn=make_prediction, inputs=[
73
+ gender_input, SeniorCitizen_input, Partner_input, Dependents_input, tenure_input,
74
+ PhoneService_input, MultipleLines_input, InternetService_input, OnlineSecurity_input,
75
+ OnlineBackup_input, DeviceProtection_input, TechSupport_input, StreamingTV_input,
76
+ StreamingMovies_input, Contract_input, PaperlessBilling_input, PaymentMethod_input,
77
+ MonthlyCharges_input, TotalCharges_input], outputs=output, title='Customer Churn Prediction App')
78
+
79
+ app.launch(share=True, debug=True)
rf_model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2caf44776f121e5e584125d07ccc7e8853ee30a26a6b3f255542daf3a0341a6b
3
+ size 46576698