liveBook · Manning

SHAP

As explained in Outlier Detection in Python

SHAP is an open-source Python library for explaining machine-learning model outputs using feature attribution methods based on Shapley values.

SHAP is a Python library that explains machine-learning and outlier-detector outputs by estimating feature attributions based on Shapley values. It provides global importance across records and local explanations for individual records. section 13.2.1

Use SHAP to:

  • Create an Explainer for a detector and calculate explanations from the relevant feature columns. section 13.2.1
  • Read bar plots for overall feature importance and beeswarm plots for importance alongside the direction of contributions. section 13.2.1
  • Inspect a local explanation for the record with the highest outlier score, while remembering that feature importance may not reveal unusual feature combinations. section 13.2.1

Abalone outlier detection

For an Isolation Forest applied to abalone data, global SHAP results identify Sex with value I and Height as influential features; one-hot encoding helps expose importance for individual categorical values. section 13.2.1

Listing 13.2 Determining the SHAP global feature importances
import shap
df = df.sort_values('IF Score')                                  #1
explainer = shap.Explainer(det)                                  #2
explanation = explainer(df[orig_features])

The implementation creates a SHAP Explainer, computes explanations, and supports global and local plots. section 13.2.1

How Outlier Detection in Python covers it

How deep it goes
Demonstrates implementation and interpretation, but defers exact feature-score relationships and notes that SHAP can be slower.
Examples
Uses abalone records, Sex and Height, bar plots, beeswarm plots, and a highest-scored local explanation.
What it assumes
Assumes a detector, scored records, and selected model features, while demonstrating the explanation workflow from detector output onward.
What you can do after
Diagnose outlier scores with SHAP global and local plots while checking whether feature combinations remain ambiguous.
How it connects
Connects feature importance with Isolation Forest, outlier detection, global explanations, and local explanations.

Also explained in

Compare how 6 books explain SHAP →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Outlier Detection in Python. The section links point to the parts of the book it draws on.