# Shap Analysis

This notebook shows [SHAP (SHapley Additive exPlanations)](https://christophm.github.io/interpretable-ml-book/shap.html) values to interpret the relative importance of features in the resulting predictions. Learn more about SHAP Analysis through this [TD Blog Post](https://blog.treasuredata.com/blog/2021/06/29/multi-touch-attribution-mta-with-shapley-values-tells-marketers-what-works-best/).

Some sample visualizations are as follows:

![](/assets/image2023-3-7_14-44-12.166d8f68ff61e1f2f90a10047ea424a9857d4d3602a5615718cfaf02e6f84326.3cb60505.png)

![](/assets/image2023-3-7_14-46-9.e510e5121e3b893e866ada234b5744acc84dd5a611475a4728e90483e89780e3.3cb60505.png)Workflow Example

Find a sample workflow here in [Treasure Boxes](https://github.com/treasure-data/treasure-boxes/blob/automl/machine-learning-box/automl/shapley.dig).


```yaml
+explain_predictions_by_shap:
  ipynb>:
    notebook: shapley
    model_name: gluon_model         # model used for prediction
    input_table: ml_test.gluon_test # test data used for prediction
```

### Parameters

| Parameter name | Parameter on Console | Description | Default Value |
|  --- | --- | --- | --- |
| docker.task_name | Docker Task Mem | Task memory size. Available values are 64g, 128g (default), 256g, 384g, or 512g depending on your contracted tiers | 128g |
| model_name | Model Name | prediction model name | - |
| input_table | Input Table | specify a TD table in dbname.table_name | - |
| shared_model | Shared Model | specify a shared model UUID | None |
| sampling_threshold | Sampling Threshold | threshold used for sampling. See the executed notebook in detail. | 10_000_000 |
| hide_table_contents | Hide Table Contents | suppress showing table contents | false |
| explain_threshold | Explain Threshold | the number of rows to explain shapley values | 200 |
| interpret_samples | Interpret Samples | the number of samples to build the surrogate model to interpret predictions | 100 |
| export_shap_values | Export Shap Values | export shapley values as a TD table | None |