Shap: How to get shap values on new samples?

Created on 3 Aug 2018  路  2Comments  路  Source: slundberg/shap

Hi Scott,

i have a question regarding the usage of the package in following scenario:

  1. Model has been trained, deployed and is available for predictions on new data
  2. After a new sample is sent to the model, i'd like to return the prediction alongside an explanation of the prediction result via shap.

What is the correct way to accomplish this?

I can think of two ways:
1.
explainer = shap.TreeExplainer(deployed_model)
shap_values = explainer.shap_values(X_new_sample)

or
2.
explainer = shap.TreeExplainer(deployed_model)
shap_values = explainer.shap_values(X_training_samples_and_new_sample)

thanks in advance
Alex

Most helpful comment

As @BrianMiner mentioned if you are just explaining a single new prediction then you should probably use the first approach (1). Then take the SHAP values for that prediction and use them how you like (for example passing them to shap.force_plot)

All 2 comments

It seems like the only relevant difference is what you do with 'shap_values' afterwards. If you inspect / plot the row of the new sample you are accomplishing your second use. If you plot the whole, you are looking at the population (say the feature importance or the dependence plot) for the model (+ 1 single new sample).

As @BrianMiner mentioned if you are just explaining a single new prediction then you should probably use the first approach (1). Then take the SHAP values for that prediction and use them how you like (for example passing them to shap.force_plot)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shoaibkhanz picture shoaibkhanz  路  4Comments

gabrielcs picture gabrielcs  路  3Comments

DiliSR picture DiliSR  路  4Comments

1vecera picture 1vecera  路  3Comments

Nithanaroy picture Nithanaroy  路  4Comments