-2

I'm using shap library to get the variables importance the issue I'm having is that I only find plots options but I need to get a list of the variables importance in order.

Luis Ramon Ramirez Rodriguez
  • 9,591
  • 27
  • 102
  • 181

1 Answers1

0

Every *Explainer class has method shap_values that returns a list of MxN numpy arrays, where M = # objects, N = # features.

Variable importance is measured by mean(|SHAP value|) as stated in the repo's README. So if your data is in a pandas dataframe, here's how to get importance-sorted features list:

per_feature_mean_shap = np.abs(shap_values[0]).mean(axis=0)
df.columns[np.argsort(per_feature_mean_shap)]
ribitskiyb
  • 429
  • 4
  • 11