Spaces:
Sleeping
Sleeping
op1009 commited on
Commit ·
014959f
1
Parent(s): 5c8128c
add app files
Browse files- Telco_churn.ipynb +0 -0
- app.py +93 -0
- dict_vectorizer.bin +0 -0
- model_lr.bin +0 -0
Telco_churn.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
app.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pickle
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
# load the saved model and DictVectorizer
|
| 7 |
+
with open('dict_vectorizer.bin', 'rb') as f_in:
|
| 8 |
+
loaded_dict_vec = pickle.load(f_in)
|
| 9 |
+
|
| 10 |
+
with open('model_lr.bin', 'rb') as f_in:
|
| 11 |
+
loaded_model = pickle.load(f_in)
|
| 12 |
+
|
| 13 |
+
# Function to make predictions
|
| 14 |
+
def predict_churn(gender, seniorcitizen, partner, dependents, phoneservice,
|
| 15 |
+
multiplelines, internetservice, onlinesecurity, onlinebackup,
|
| 16 |
+
deviceprotection, techsupport, streamingtv, streamingmovies,
|
| 17 |
+
contract, paperlessbilling, paymentmethod, tenure,
|
| 18 |
+
monthlycharges, totalcharges):
|
| 19 |
+
|
| 20 |
+
customer = {
|
| 21 |
+
'gender': gender,
|
| 22 |
+
'seniorcitizen': seniorcitizen,
|
| 23 |
+
'partner': partner,
|
| 24 |
+
'dependents': dependents,
|
| 25 |
+
'phoneservice': phoneservice,
|
| 26 |
+
'multiplelines': multiplelines,
|
| 27 |
+
'internetservice': internetservice,
|
| 28 |
+
'onlinesecurity': onlinesecurity,
|
| 29 |
+
'onlinebackup': onlinebackup,
|
| 30 |
+
'deviceprotection': deviceprotection,
|
| 31 |
+
'techsupport': techsupport,
|
| 32 |
+
'streamingtv': streamingtv,
|
| 33 |
+
'streamingmovies': streamingmovies,
|
| 34 |
+
'contract': contract,
|
| 35 |
+
'paperlessbilling': paperlessbilling,
|
| 36 |
+
'paymentmethod': paymentmethod,
|
| 37 |
+
'tenure': tenure,
|
| 38 |
+
'monthlycharges': monthlycharges,
|
| 39 |
+
'totalcharges': totalcharges
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
labels = ['No Churn', 'Churn']
|
| 43 |
+
|
| 44 |
+
X = loaded_dict_vec.transform([customer])
|
| 45 |
+
y_pred = loaded_model.predict_proba(X)[0,:]
|
| 46 |
+
churn_probability = y_pred
|
| 47 |
+
|
| 48 |
+
return {labels[i]: float(y_pred[i]) for i in range(2)}
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
with gr.Blocks() as demo:
|
| 52 |
+
gr.Markdown("<h1 style='text-align: center;'>Telecom Customer Churn Prediction</h1>")
|
| 53 |
+
gr.Markdown("<h3 style='text-align: center;'>Predict the probability of a customer churning based on their demographics and service usage.</h3>")
|
| 54 |
+
|
| 55 |
+
with gr.Row():
|
| 56 |
+
gender = gr.components.Dropdown(['male', 'female'], value='male', label="Gender")
|
| 57 |
+
senior_citizen = gr.components.Radio([0, 1], value=0, label="Senior Citizen")
|
| 58 |
+
partner = gr.components.Radio(['yes', 'no'], value='yes', label="Partner")
|
| 59 |
+
dependents = gr.components.Radio(['yes', 'no'], value='yes', label="Dependents")
|
| 60 |
+
|
| 61 |
+
with gr.Row():
|
| 62 |
+
phone_service = gr.components.Radio(['yes', 'no'], value='yes', label="Phone Service")
|
| 63 |
+
multiple_lines = gr.components.Dropdown(['no_phone_service', 'no', 'yes'], label="Multiple Lines")
|
| 64 |
+
internet_service = gr.components.Dropdown(['dsl', 'fiber_optic', 'no'], label="Internet Service")
|
| 65 |
+
online_security = gr.components.Dropdown(['no', 'yes', 'no_internet_service'], label="Online Security")
|
| 66 |
+
online_backup = gr.components.Dropdown(['yes', 'no', 'no_internet_service'], label="Online Backup")
|
| 67 |
+
device_protection = gr.components.Dropdown(['no', 'yes', 'no_internet_service'], label="Device Protection")
|
| 68 |
+
tech_support = gr.components.Dropdown(['no', 'yes', 'no_internet_service'], label="Tech Support")
|
| 69 |
+
|
| 70 |
+
with gr.Row():
|
| 71 |
+
streaming_tv = gr.Dropdown(label="Streaming TV", choices=['no', 'yes', 'no_internet_service'], value="no")
|
| 72 |
+
streaming_movies = gr.Dropdown(label="Streaming Movies", choices=['no', 'yes', 'no_internet_service'], value="no")
|
| 73 |
+
|
| 74 |
+
with gr.Row():
|
| 75 |
+
contract = gr.components.Dropdown(['month-to-month', 'one_year', 'two_year'], value='month-to-month', label="Contract")
|
| 76 |
+
paperless_billing = gr.components.Radio(['yes', 'no'], value='no', label="Paperless Billing")
|
| 77 |
+
payment_method = gr.components.Dropdown(['electronic_check', 'mailed_check', 'bank_transfer_(automatic)', 'credit_card_(automatic)'], value='electronic_check', label="Payment Method")
|
| 78 |
+
tenure = gr.components.Number(label="Tenure (Months)", minimum=0, maximum=1000)
|
| 79 |
+
monthly_charges = gr.components.Number(label="Monthly Charges (₹)", minimum=0, maximum=10000)
|
| 80 |
+
total_charges = gr.components.Number(label="Total Charges (₹)", minimum=0, maximum=1000000)
|
| 81 |
+
|
| 82 |
+
submit_btn = gr.Button("Submit")
|
| 83 |
+
|
| 84 |
+
output_label = gr.Label(label="Churn Probability")
|
| 85 |
+
|
| 86 |
+
submit_btn.click(predict_churn, inputs=[gender, senior_citizen, partner, dependents,
|
| 87 |
+
phone_service, multiple_lines,
|
| 88 |
+
internet_service, online_security, online_backup, device_protection, tech_support,
|
| 89 |
+
streaming_tv, streaming_movies, contract, paperless_billing, payment_method, tenure,
|
| 90 |
+
monthly_charges, total_charges
|
| 91 |
+
], outputs=output_label)
|
| 92 |
+
|
| 93 |
+
demo.launch()
|
dict_vectorizer.bin
ADDED
|
Binary file (1.43 kB). View file
|
|
|
model_lr.bin
ADDED
|
Binary file (1.08 kB). View file
|
|
|