Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import joblib
|
| 4 |
+
|
| 5 |
+
le=joblib.load('le_col.pkl')
|
| 6 |
+
min_max=joblib.load('MinMax.pkl')
|
| 7 |
+
lr=joblib.load('model.pkl')
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
le_col=['gender','Partner','Dependents','PhoneService','PaperlessBilling','MultipleLines','InternetService','OnlineSecurity','OnlineBackup','DeviceProtection','TechSupport','StreamingTV','StreamingMovies','Contract','PaymentMethod']
|
| 11 |
+
MinMax=['TotalCharges','MonthlyCharges','tenure']
|
| 12 |
+
|
| 13 |
+
def prediction_churn_model(gr,sc,pr,dp,t,ps,mp,Is,os,ob,dd,ts,st,sm,cr,pb,pm,mc,tc):
|
| 14 |
+
try:
|
| 15 |
+
input_data=pd.DataFrame({
|
| 16 |
+
'gender':[gr],
|
| 17 |
+
'SeniorCitizen':[sc],
|
| 18 |
+
'Partner':[pr],
|
| 19 |
+
'Dependents':[dp],
|
| 20 |
+
'tenure':[t],
|
| 21 |
+
'PhoneService':[ps],
|
| 22 |
+
'MultipleLines':[mp],
|
| 23 |
+
'InternetService':[Is],
|
| 24 |
+
'OnlineSecurity':[os],
|
| 25 |
+
'OnlineBackup':[ob],
|
| 26 |
+
'DeviceProtection':[dd],
|
| 27 |
+
'TechSupport':[ts],
|
| 28 |
+
'StreamingTV':[st],
|
| 29 |
+
'StreamingMovies':[sm],
|
| 30 |
+
'Contract':[cr],
|
| 31 |
+
'PaperlessBilling':[pb],
|
| 32 |
+
'PaymentMethod':[pm],
|
| 33 |
+
'MonthlyCharges':[mc],
|
| 34 |
+
'TotalCharges':[tc]
|
| 35 |
+
})
|
| 36 |
+
for col in le_col:
|
| 37 |
+
input_data[col]=le[col].transform(input_data[col])
|
| 38 |
+
input_data[MinMax]=min_max.transform(input_data[MinMax])
|
| 39 |
+
prediction=lr.predict(input_data)
|
| 40 |
+
if prediction[0]==0:
|
| 41 |
+
return 'No'
|
| 42 |
+
else:
|
| 43 |
+
return 'Yes'
|
| 44 |
+
except Exception as e:
|
| 45 |
+
return str(e)
|
| 46 |
+
gr.Interface(
|
| 47 |
+
inputs=[
|
| 48 |
+
gr.Dropdown(['Female', 'Male'],label='gender'),
|
| 49 |
+
gr.Number(label='SeniorCitizen'),
|
| 50 |
+
gr.Dropdown(['No','Yes'],label='Partner'),
|
| 51 |
+
gr.Dropdown(['No','Yes'],label='Dependents'),
|
| 52 |
+
gr.Number(label='tenure'),
|
| 53 |
+
gr.Dropdown(['Yes','No'],label='PhoneService'),
|
| 54 |
+
gr.Dropdown(['No','Yes'],label='MultipleLines'),
|
| 55 |
+
gr.Dropdown(['Fiber optic','DSL','No'],label='InternetService'),
|
| 56 |
+
gr.Dropdown(['No','Yes','No internet service'],label='OnlineSecurity'),
|
| 57 |
+
gr.Dropdown(['No','Yes','No internet service'],label='OnlineBackup'),
|
| 58 |
+
gr.Dropdown(['No','Yes','No internet service'],label='DeviceProtection'),
|
| 59 |
+
gr.Dropdown(['No','Yes','No internet service'],label='TechSupport'),
|
| 60 |
+
gr.Dropdown(['No','Yes','No internet service'],label='StreamingTV'),
|
| 61 |
+
gr.Dropdown(['No','Yes','No internet service'],label='StreamingMovies'),
|
| 62 |
+
gr.Dropdown(['Month-to-month','Two year','One year'],label='Contract'),
|
| 63 |
+
gr.Dropdown(['Yes','No'],label='PaperlessBilling'),
|
| 64 |
+
gr.Dropdown(['Electroniccheck', 'Mailedcheck', 'Banktransfer', 'Creditcard'],label='PaymentMethod'),
|
| 65 |
+
gr.Number(label='MonthlyCharges'),
|
| 66 |
+
gr.Number(label='TotalCharges')
|
| 67 |
+
],
|
| 68 |
+
fn=prediction_churn_model,
|
| 69 |
+
outputs=gr.Textbox(label='Prediction'),
|
| 70 |
+
title='Prediction Telecoum Churn Model'
|
| 71 |
+
).launch()
|