penscola commited on
Commit
9411cf2
1 Parent(s): 896cd49

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -8
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  import pandas as pd
3
  import joblib
 
4
  from sklearn.pipeline import Pipeline
5
  from sklearn.impute import SimpleImputer
6
  from sklearn.compose import ColumnTransformer
@@ -8,7 +9,7 @@ from sklearn.preprocessing import StandardScaler, OneHotEncoder
8
  from sklearn.linear_model import LogisticRegression
9
 
10
  # Load the saved full pipeline from the file
11
- full_pipeline = joblib.load('pipe.pkl')
12
 
13
  # Define the predict function
14
  def predict(gender, SeniorCitizen, Partner, Dependents, Contract, tenure, MonthlyCharges,
@@ -40,16 +41,22 @@ def predict(gender, SeniorCitizen, Partner, Dependents, Contract, tenure, Monthl
40
 
41
 
42
  # Make predictions using the loaded logistic regression model
43
- predictions = full_pipeline.predict(input_data)
 
 
 
 
 
44
 
45
  #return predictions[0]
46
- if predictions[0] == "Yes":
47
- return "Churn"
 
48
  else:
49
- return "Not Churn"
50
-
51
  # Setting Gradio App Interface
52
- with gr.Blocks(css=".gradio-container {background-color: grey}") as demo:
53
  gr.Markdown("# Teleco Customer Churn Prediction #\n*This App allows the user to predict whether a customer will churn or not by entering values in the given fields. Any field left blank takes the default value.*")
54
 
55
  # Receiving ALL Input Data here
@@ -106,7 +113,7 @@ with gr.Blocks(css=".gradio-container {background-color: grey}") as demo:
106
 
107
  def clear():
108
  output.value = ""
109
- return None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None
110
 
111
  clear_btn = gr.Button("Reset", variant="primary")
112
  clear_btn.click(fn=clear, inputs=None, outputs=output)
 
1
  import gradio as gr
2
  import pandas as pd
3
  import joblib
4
+ import numpy as np
5
  from sklearn.pipeline import Pipeline
6
  from sklearn.impute import SimpleImputer
7
  from sklearn.compose import ColumnTransformer
 
9
  from sklearn.linear_model import LogisticRegression
10
 
11
  # Load the saved full pipeline from the file
12
+ full_pipeline = joblib.load('src\pipe.pkl')
13
 
14
  # Define the predict function
15
  def predict(gender, SeniorCitizen, Partner, Dependents, Contract, tenure, MonthlyCharges,
 
41
 
42
 
43
  # Make predictions using the loaded logistic regression model
44
+ #predict probabilities
45
+ predictions = full_pipeline.predict_proba(input_data)
46
+ #take the index of the maximum probability
47
+ index=np.argmax(predictions)
48
+ higher_pred_prob=round((predictions[0][index])*100)
49
+
50
 
51
  #return predictions[0]
52
+ print(f'[Info] Predicted probabilities{predictions},{full_pipeline.classes_}')
53
+ if full_pipeline.classes_[index] == "Yes":
54
+ return f"This Customer is likely to Churn\nWe are {higher_pred_prob}% confident About this prediction"
55
  else:
56
+ return f"This Customer is Not likely to Churn \nWe are {higher_pred_prob}% confident About this prediction"
57
+
58
  # Setting Gradio App Interface
59
+ with gr.Blocks(css=".gradio-container {background-color:grey }",theme=gr.themes.Base(primary_hue='blue'),title='Uriel') as demo:
60
  gr.Markdown("# Teleco Customer Churn Prediction #\n*This App allows the user to predict whether a customer will churn or not by entering values in the given fields. Any field left blank takes the default value.*")
61
 
62
  # Receiving ALL Input Data here
 
113
 
114
  def clear():
115
  output.value = ""
116
+ return 'Predicted values have been reset'
117
 
118
  clear_btn = gr.Button("Reset", variant="primary")
119
  clear_btn.click(fn=clear, inputs=None, outputs=output)