Is it possible to the SHAP value for each feature?
From the docstrings of the shap_values method, we can see that:
For models with a single output this returns a matrix of SHAP values
(# samples x # features)
So unless you have a different situation/case, you should be getting # samples arrays with SHAP values for each feature when calling this method.
Do let me know if this does not work for you.
Unless I'm mistaken, you can simply average over the SHAP values for each sample for each feature. e.g. here's a snippet:
mean_shap_feature_values = pd.DataFrame(shap_values, columns=your_xs_dataframe.columns).abs().mean(axis=0).sort_values(ascending=False)
These should align with your simple SHAP importance plot (summary_plot with plot_type='bar').
It would be a nice convenience function for SHAP to expose these "importances" with an API like SKL's rf.feature_importances_ or similar.
Most helpful comment
From the docstrings of the
shap_valuesmethod, we can see that:So unless you have a different situation/case, you should be getting
# samplesarrays with SHAP values for each feature when calling this method.Do let me know if this does not work for you.