FKBaffour commited on
Commit
412e3a9
0 Parent(s):

Duplicate from FKBaffour/Customer_Churn_Prediction_App

Browse files
Files changed (5) hide show
  1. .gitattributes +34 -0
  2. ML_items +0 -0
  3. README.md +13 -0
  4. app.py +125 -0
  5. requirements.txt +8 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
ML_items ADDED
Binary file (35.1 kB). View file
 
README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Gradio Customer Churn Prediction App
3
+ emoji: 🏢
4
+ colorFrom: indigo
5
+ colorTo: purple
6
+ sdk: gradio
7
+ sdk_version: 3.15.0
8
+ app_file: app.py
9
+ pinned: false
10
+ duplicated_from: FKBaffour/Customer_Churn_Prediction_App
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Importing required Libraries
2
+ from IPython.utils.py3compat import encode
3
+ import gradio as gr
4
+ import numpy as np
5
+ import pandas as pd
6
+ import pickle
7
+
8
+
9
+ # Loading Machine Learning Objects
10
+ def load_saved_objets(filepath='ML_items'):
11
+ "Function to load saved objects"
12
+
13
+ with open(filepath, 'rb') as file:
14
+ loaded_object = pickle.load(file)
15
+
16
+ return loaded_object
17
+
18
+ # Instantiating ML_items
19
+ loaded_object = load_saved_objets()
20
+ pipeline_of_my_app = loaded_object["pipeline"]
21
+ num_cols = loaded_object['numeric_columns']
22
+ cat_cols = loaded_object['categorical_columns']
23
+ encoder_categories = loaded_object["encoder_categories"]
24
+
25
+ # Main function to collect the inputs process them and outpuT the predicition
26
+ def predict_churn(
27
+ TotalCharges,
28
+ MonthlyCharges,
29
+ tenure,
30
+ StreamingTV,
31
+ PaperlessBilling,
32
+ DeviceProtection,
33
+ TechSupport,
34
+ InternetService,
35
+ OnlineSecurity,
36
+ StreamingMovies,
37
+ PaymentMethod,
38
+ Dependents,
39
+ Parter,
40
+ tenure_group,
41
+ OnlineBackup,
42
+ gender,
43
+ SeniorCitizen,
44
+ MultipleLines,
45
+ Contract,
46
+ PhoneService,
47
+ ):
48
+
49
+ df = pd.DataFrame(
50
+ [
51
+ [
52
+ TotalCharges,
53
+ MonthlyCharges,
54
+ tenure,
55
+ StreamingTV,
56
+ PaperlessBilling,
57
+ DeviceProtection,
58
+ TechSupport,
59
+ InternetService,
60
+ OnlineSecurity,
61
+ StreamingMovies,
62
+ PaymentMethod,
63
+ Dependents,
64
+ Parter,
65
+ tenure_group,
66
+ OnlineBackup,
67
+ gender,
68
+ SeniorCitizen,
69
+ MultipleLines,
70
+ Contract,
71
+ PhoneService,
72
+ ]
73
+ ],
74
+ columns= num_cols + cat_cols,
75
+ ).replace("", np.nan)
76
+
77
+ df[cat_cols] = df[cat_cols].astype("object")
78
+
79
+ # Passing data to pipeline to make prediction
80
+ output = pipeline_of_my_app.predict(df)
81
+
82
+ # Labelling Model output
83
+ if output == 0:
84
+ model_output = "No"
85
+ else:
86
+ model_output = "Yes"
87
+
88
+ return model_output
89
+
90
+
91
+ # Setting up app interface and data inputs
92
+ inputs = []
93
+
94
+ with gr.Blocks() as demo:
95
+
96
+ # Setting Titles for App
97
+ gr.Markdown("<h2 style='text-align: center;'> Customer Churn Prediction App </h2> ", unsafe_allow_html=True)
98
+ gr.Markdown("<h6 style='text-align: center;'> (Fill in the details below and click on PREDICT button to make a prediction for Customer Churn) </h6> ", unsafe_allow_html=True)
99
+
100
+ with gr.Column(): #main frame
101
+
102
+ with gr.Row(): #col 1 : for num features
103
+
104
+ for i in num_cols:
105
+ inputs.append(gr.Number(label=f"Input {i} "))
106
+
107
+ with gr.Row(): #col 2 : for cat features
108
+
109
+ for (lab, choices) in zip(cat_cols, encoder_categories):
110
+ inputs.append(gr.inputs.Dropdown(
111
+ choices=choices.tolist(),
112
+ type="value",
113
+ label=f"Select {lab}",
114
+ default=choices.tolist()[0],))
115
+ # Setting up preediction Button
116
+ with gr.Row():
117
+ make_prediction = gr.Button("Predict")
118
+
119
+ # Setting up prediction output row
120
+ with gr.Row():
121
+ output_prediction = gr.Text(label="Will Customer Churn?")
122
+ make_prediction.click(predict_churn, inputs, output_prediction)
123
+
124
+ # Launching app
125
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+
2
+ IPython
3
+ pandas==1.4.2
4
+ numpy==1.21.5
5
+ seaborn==0.11.2
6
+ shap==0.41.0
7
+ gradio
8
+ scikit-learn==1.1.3