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





