Member-only story

Introduction to SHAP with Python

How to create and interpret SHAP plots: waterfall, force, mean SHAP, beeswarm and dependence

Conor O'Sullivan
TDS Archive
10 min readDec 19, 2021

--

Updated: 12 March 2023

A SHAP beeswarm plot enlarged and rotated 90 degrees
(source: author)

SHAP is the most powerful Python package for understanding and debugging your models. It can tell us how each model feature has contributed to an individual prediction. By aggregating SHAP values, we can also understand trends across multiple predictions. With a few lines of code, we are able to identify and visualise important relationships in our model.

We walk through the code used to calculate and display SHAP values. This includes explanations of the following SHAP plots:

  • Waterfall plot
  • Force plots
  • Mean SHAP plot
  • Beeswarm plot
  • Dependence plots

We do this for a model that predicts a continuous target variable. If you want an explanation for classification, please see SHAP for Binary and Multiclass Target Variables. You can find the full project on GitHub.

There is also a video that goes over the content of this article. If you want more, check out my SHAP course. You can get free access if you sign up for my Newsletter :)

--

--

TDS Archive
TDS Archive

Published in TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial intelligence writing from the former Towards Data Science Medium publication.

Conor O'Sullivan
Conor O'Sullivan

Written by Conor O'Sullivan

PhD Student | Writer | Houseplant Addict | Follow me for articles on IML, XAI, Algorithm Fairness and Remote Sensing

Responses (11)