Spaces:
Runtime error
Runtime error
try to fix force plot
Browse files
app.py
CHANGED
@@ -66,10 +66,10 @@ with gr.Blocks() as demo:
|
|
66 |
with gr.Column():
|
67 |
summary_plot = gr.Plot()
|
68 |
with gr.Row():
|
69 |
-
with gr.Column():
|
70 |
-
interaction_plot = gr.Plot()
|
71 |
with gr.Column():
|
72 |
force_plot = gr.Plot()
|
|
|
|
|
73 |
|
74 |
def submit_inputs(
|
75 |
age_input,
|
@@ -170,6 +170,16 @@ with gr.Blocks() as demo:
|
|
170 |
feature_names=["age", "bmi", "hba1c", "glucose"],
|
171 |
)
|
172 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
# fig4 = plt.figure(figsize=(3, 3))
|
174 |
# plt.title("SHAP Interaction Plot")
|
175 |
# shap_interaction_values = explainer.shap_interaction_values(transformed_df)
|
@@ -179,17 +189,6 @@ with gr.Blocks() as demo:
|
|
179 |
# feature_names=["age", "bmi", "hba1c", "glucose"],
|
180 |
# )
|
181 |
|
182 |
-
fig5 = plt.figure(figsize=(3, 3))
|
183 |
-
plt.title("SHAP Force Plot")
|
184 |
-
# Assuming you have the SHAP values for the predicted class of the single row df
|
185 |
-
shap.force_plot(
|
186 |
-
explainer.expected_value[predicted_class],
|
187 |
-
shap_values_for_predicted_class,
|
188 |
-
df.iloc[0],
|
189 |
-
feature_names=["age", "bmi", "hba1c", "glucose"],
|
190 |
-
matplotlib=True,
|
191 |
-
)
|
192 |
-
|
193 |
## save user's data in hopsworks
|
194 |
if consent_input == True:
|
195 |
user_data_fg = fs.get_or_create_feature_group(
|
@@ -202,7 +201,7 @@ with gr.Blocks() as demo:
|
|
202 |
user_data_df["diabetes"] = existent_info_input
|
203 |
user_data_fg.insert(user_data_df)
|
204 |
print("inserted new user data to hopsworks", user_data_df)
|
205 |
-
return res, fig, fig2, fig3,
|
206 |
|
207 |
btn.click(
|
208 |
submit_inputs,
|
@@ -214,7 +213,7 @@ with gr.Blocks() as demo:
|
|
214 |
existent_info_input,
|
215 |
consent_input,
|
216 |
],
|
217 |
-
outputs=[output, mean_plot, waterfall_plot, summary_plot,
|
218 |
)
|
219 |
|
220 |
demo.launch()
|
|
|
66 |
with gr.Column():
|
67 |
summary_plot = gr.Plot()
|
68 |
with gr.Row():
|
|
|
|
|
69 |
with gr.Column():
|
70 |
force_plot = gr.Plot()
|
71 |
+
with gr.Column():
|
72 |
+
interaction_plot = gr.Plot()
|
73 |
|
74 |
def submit_inputs(
|
75 |
age_input,
|
|
|
170 |
feature_names=["age", "bmi", "hba1c", "glucose"],
|
171 |
)
|
172 |
|
173 |
+
fig4 = plt.figure(figsize=(3, 3))
|
174 |
+
plt.title("SHAP Force Plot")
|
175 |
+
|
176 |
+
shap.force_plot(
|
177 |
+
explainer.expected_value[predicted_class],
|
178 |
+
shap_values_for_predicted_class,
|
179 |
+
df.iloc[0],
|
180 |
+
feature_names=["age", "bmi", "hba1c", "glucose"],
|
181 |
+
)
|
182 |
+
|
183 |
# fig4 = plt.figure(figsize=(3, 3))
|
184 |
# plt.title("SHAP Interaction Plot")
|
185 |
# shap_interaction_values = explainer.shap_interaction_values(transformed_df)
|
|
|
189 |
# feature_names=["age", "bmi", "hba1c", "glucose"],
|
190 |
# )
|
191 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
## save user's data in hopsworks
|
193 |
if consent_input == True:
|
194 |
user_data_fg = fs.get_or_create_feature_group(
|
|
|
201 |
user_data_df["diabetes"] = existent_info_input
|
202 |
user_data_fg.insert(user_data_df)
|
203 |
print("inserted new user data to hopsworks", user_data_df)
|
204 |
+
return res, fig, fig2, fig3, fig4
|
205 |
|
206 |
btn.click(
|
207 |
submit_inputs,
|
|
|
213 |
existent_info_input,
|
214 |
consent_input,
|
215 |
],
|
216 |
+
outputs=[output, mean_plot, waterfall_plot, summary_plot, force_plot],
|
217 |
)
|
218 |
|
219 |
demo.launch()
|