Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,23 +7,24 @@ import numpy as np
|
|
7 |
import matplotlib.pyplot as plt
|
8 |
|
9 |
#load the model from disk
|
10 |
-
loaded_model = pickle.load(open("
|
11 |
|
12 |
#Setup SHAP
|
13 |
explainer = shap.Explainer(loaded_model) #DO NOT CHANGE PER INSTRUCTIONS
|
14 |
|
15 |
#Main Function for Server
|
16 |
-
def main_func(
|
17 |
-
new_row = pd.DataFrame.from_dict({'
|
18 |
-
'
|
19 |
-
'
|
|
|
20 |
|
21 |
prob = loaded_model.predict_proba(new_row)
|
22 |
|
23 |
shap_values = explainer(new_row)
|
24 |
# plot = shap.force(shap_values[0], matplotlib=True, figsize(30,30), show = False)
|
25 |
-
# plot = shap.plots.waterfall(shap_values[0], max_display =
|
26 |
-
plot = shap.plots.bar(shap_values[0], max_display =
|
27 |
|
28 |
plt.tight_layout()
|
29 |
local_plot = plt.gcf()
|
@@ -35,11 +36,11 @@ def main_func(Engagement,WorkLifeBalance,Voice,Workload,LearningDevelopment,Meri
|
|
35 |
#Create UI
|
36 |
title = "**Employee Turnover Predictor & Intrepreter**"
|
37 |
description1 = """
|
38 |
-
This app takes
|
39 |
"""
|
40 |
|
41 |
description2 = """
|
42 |
-
To use the app, click on one of the examples, or adjust the values of the
|
43 |
"""
|
44 |
|
45 |
with gr.Blocks(title = title) as demo:
|
@@ -50,12 +51,13 @@ with gr.Blocks(title = title) as demo:
|
|
50 |
gr.Markdown("""---""")
|
51 |
with gr.Row():
|
52 |
with gr.Column():
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
59 |
submit_btn = gr.Button("Analyze")
|
60 |
with gr.Column(visible=True,scale=1, min_width=600) as output_col:
|
61 |
label = gr.Label(label = "Predicted Label")
|
@@ -63,13 +65,13 @@ with gr.Blocks(title = title) as demo:
|
|
63 |
|
64 |
submit_btn.click(
|
65 |
main_func,
|
66 |
-
[
|
67 |
[label,local_plot], api_name="Employee_Turnover"
|
68 |
)
|
69 |
|
70 |
gr.Markdown('### Click on any of the examples below to see how it works:')
|
71 |
-
gr.Examples([[4,4,4,4,5,5], [5,4,5,4,4,4]],
|
72 |
-
[
|
73 |
[label,local_plot], main_func, cache_examples=True)
|
74 |
|
75 |
demo.launch()
|
|
|
7 |
import matplotlib.pyplot as plt
|
8 |
|
9 |
#load the model from disk
|
10 |
+
loaded_model = pickle.load(open("h25_xgb_hyperopt.pkl", 'rb'))
|
11 |
|
12 |
#Setup SHAP
|
13 |
explainer = shap.Explainer(loaded_model) #DO NOT CHANGE PER INSTRUCTIONS
|
14 |
|
15 |
#Main Function for Server
|
16 |
+
def main_func(PassionateAtWork,Workload,SupportiveGM,WorkEnvironment,Informed,LearningDevelopment,JobSecurity):
|
17 |
+
new_row = pd.DataFrame.from_dict({'PassionateAtWork':PassionateAtWork, 'Workload':Workload,
|
18 |
+
'SupportiveGM':SupportiveGM,'WorkEnvironment':WorkEnvironment, 'Informed':Informed,
|
19 |
+
'LearningDevelopment': LearningDevelopment, 'JobSecurity':JobSecurity},
|
20 |
+
orient = 'index').transpose()
|
21 |
|
22 |
prob = loaded_model.predict_proba(new_row)
|
23 |
|
24 |
shap_values = explainer(new_row)
|
25 |
# plot = shap.force(shap_values[0], matplotlib=True, figsize(30,30), show = False)
|
26 |
+
# plot = shap.plots.waterfall(shap_values[0], max_display = 7, show = False)
|
27 |
+
plot = shap.plots.bar(shap_values[0], max_display = 7, order=shap.Explanation.abs, show_data = 'auto', show = False)
|
28 |
|
29 |
plt.tight_layout()
|
30 |
local_plot = plt.gcf()
|
|
|
36 |
#Create UI
|
37 |
title = "**Employee Turnover Predictor & Intrepreter**"
|
38 |
description1 = """
|
39 |
+
This app takes seven inputs about employees' satisfaction with different aspects of their work (such as Passionate at Work, ...) and predicts whether the employee intends to stay with the employer or leave. There are two outputs from the app: 1- the predicted probability of stay or leave, 2- Shapley's force-plot which visualizes the extent to which each factor impacts the stay/ leave prediction.
|
40 |
"""
|
41 |
|
42 |
description2 = """
|
43 |
+
To use the app, click on one of the examples, or adjust the values of the seven employee satisfaction factors, and click Analyze.
|
44 |
"""
|
45 |
|
46 |
with gr.Blocks(title = title) as demo:
|
|
|
51 |
gr.Markdown("""---""")
|
52 |
with gr.Row():
|
53 |
with gr.Column():
|
54 |
+
PassionateAtWork = gr.Slider(label= "Passionate At Work", minimum = 1, maximum = 5, value = 4, step = .1)
|
55 |
+
Workload = gr.Slider(label= "Workload", minimum = 1, maximum = 5, value = 4, step = .1)
|
56 |
+
SupportiveGM = gr.Slider(label= "Supportive GM", minimum = 1, maximum = 5, value = 4, step = .1)
|
57 |
+
WorkEnvironment = gr.Slider(label= "Work Environment", minimum = 1, maximum = 5, value = 4, step = .1)
|
58 |
+
Informed = gr.Slider(label= "Informed", minimum = 1, maximum = 5, value = 4, step = .1)
|
59 |
+
LearningDevelopment = gr.Slider(label= "Learning Development", minimum = 1, maximum = 5, value = 4, step = .1)
|
60 |
+
JobSecurity = gr.Slider(label= "Job Security", minimum = 1, maximum = 5, value = 4, step = .1)
|
61 |
submit_btn = gr.Button("Analyze")
|
62 |
with gr.Column(visible=True,scale=1, min_width=600) as output_col:
|
63 |
label = gr.Label(label = "Predicted Label")
|
|
|
65 |
|
66 |
submit_btn.click(
|
67 |
main_func,
|
68 |
+
[PassionateAtWork,Workload,SupportiveGM,WorkEnvironment,Informed,LearningDevelopment,JobSecurity],
|
69 |
[label,local_plot], api_name="Employee_Turnover"
|
70 |
)
|
71 |
|
72 |
gr.Markdown('### Click on any of the examples below to see how it works:')
|
73 |
+
gr.Examples([[4,4,4,4,5,5,4], [5,4,5,4,4,4,5]],
|
74 |
+
[PassionateAtWork,Workload,SupportiveGM,WorkEnvironment,Informed,LearningDevelopment,JobSecurity],
|
75 |
[label,local_plot], main_func, cache_examples=True)
|
76 |
|
77 |
demo.launch()
|