1

I am currently trying to plot a set of 29 features on a SHAP summary plot. However, I am struggling to find the code necessary to do so.

I want to plot the result of the Neural Network model using SHAP and I am using Python. I have 29 predictor variables and 5 response variables.

First, the summary plot only includes the top 20 features; however, I want the plot to include all 28 features.

Second, I would like to display the SHAP values in the summary plot; however, I cannot find a way to do it.

Here is my code, and hope someone can help. Thanks in advance!

`# Create the explainer`

`explainer = shap.DeepExplainer(model, PRED_train)`

`# Compute SHAP values`

`shap_values = explainer.shap_values(PRED_test)`

`# Plot the summary of feature importance`

`shap.summary_plot(shap_values, features=PRED_test, plot_type='bar')`

I have checked the GitHub code and it seems SHAP cannot do these two as a default, so I am hoping someone can help me by guiding me how I should revise my code.

PRED_test is not a DataFrame so cannot use np.

I tried below but it does not work:

np.abs(shap_values.values).mean(axis=0)
Ellie Moh
  • 11
  • 2

1 Answers1

0

Use shap.plot.bar():

It has a max_display argument, and shows average absolute SHAP values as numbers. If you want the plot to show SHAP values (as you write), go for a bee swarm plot.

Michael M
  • 880
  • 7
  • 10