Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -67,23 +67,12 @@ def main_func(Department, ChainScale, SupportiveGM, Merit, LearningDevelopment,
|
|
67 |
shap_values = explainer(new_row)
|
68 |
|
69 |
fig, ax = plt.subplots(figsize=(8, 4))
|
70 |
-
|
71 |
-
features = new_row.columns # Feature names
|
72 |
-
|
73 |
-
colors = ['#FF0000' if v < 0 else '#1E4380' for v in values]
|
74 |
-
sorted_indices = np.argsort(np.abs(values))[-6:] # Select top 6 features
|
75 |
-
sorted_values = values[sorted_indices]
|
76 |
-
sorted_features = [features[i] for i in sorted_indices]
|
77 |
-
sorted_colors = [colors[i] for i in sorted_indices]
|
78 |
-
ax.barh(sorted_features, sorted_values, color=sorted_colors)
|
79 |
-
ax.set_xlabel("SHAP Value Impact")
|
80 |
-
ax.set_title("Feature Importance (SHAP)")
|
81 |
-
|
82 |
plt.tight_layout()
|
83 |
local_plot = plt.gcf()
|
84 |
plt.close()
|
85 |
|
86 |
-
return {"Leave": float(prob[0][0]), "Stay":
|
87 |
|
88 |
# Create the UI
|
89 |
title = "**Mod 3 Team 5: Employee Turnover Predictor & Interpreter**"
|
@@ -141,8 +130,8 @@ with gr.Blocks(title=title) as demo:
|
|
141 |
submit_btn = gr.Button("Analyze")
|
142 |
|
143 |
with gr.Column(visible=True, scale=1, min_width=600) as output_col:
|
144 |
-
label = gr.Label(label="Predicted
|
145 |
-
local_plot = gr.Plot(label='SHAP Analysis')
|
146 |
|
147 |
submit_btn.click(
|
148 |
main_func,
|
@@ -166,3 +155,4 @@ with gr.Blocks(title=title) as demo:
|
|
166 |
)
|
167 |
|
168 |
demo.launch()
|
|
|
|
67 |
shap_values = explainer(new_row)
|
68 |
|
69 |
fig, ax = plt.subplots(figsize=(8, 4))
|
70 |
+
shap.waterfall_plot(shap_values[0]) # Corrected to use waterfall plot
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
plt.tight_layout()
|
72 |
local_plot = plt.gcf()
|
73 |
plt.close()
|
74 |
|
75 |
+
return {"Leave": float(prob[0][0]), "Stay": float(prob[0][1])}, local_plot
|
76 |
|
77 |
# Create the UI
|
78 |
title = "**Mod 3 Team 5: Employee Turnover Predictor & Interpreter**"
|
|
|
130 |
submit_btn = gr.Button("Analyze")
|
131 |
|
132 |
with gr.Column(visible=True, scale=1, min_width=600) as output_col:
|
133 |
+
label = gr.Label(label="Predicted Intent to Stay vs Leave")
|
134 |
+
local_plot = gr.Plot(label='SHAP Waterfall Analysis')
|
135 |
|
136 |
submit_btn.click(
|
137 |
main_func,
|
|
|
155 |
)
|
156 |
|
157 |
demo.launch()
|
158 |
+
|