shap

Compute and validate SHAP feature attributions for machine-learning model explanations.

1|Updated Aug 24, 2026
One-click install
npx skills add https://github.com/CliffVale/opencode-free-setup --skill shap-cliffvale
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: shap
Source: https://github.com/CliffVale/opencode-free-setup/tree/main/skills/shap
Command: npx skills add https://github.com/CliffVale/opencode-free-setup --skill shap-cliffvale

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires shap, numpy, pandas, scikit-learn, matplotlib, and includes scripts (resource) and references (resource) components.

What problem does it solve? Explaining why a fitted machine-learning model produced a specific prediction is difficult to do rigorously, and misconfigured SHAP analyses silently produce misleading attributions. This Skill guides explainer and masker selection, output-space handling, additivity validation, and correct visualization so explanations are reproducible and defensible. ## Core Features & Use Cases - Explainer and masker selection: Decision tables for TreeExplainer, LinearExplainer, PermutationExplainer, PartitionExplainer, DeepExplainer, and more, matched to model type and feature structure. - Validated explanations: Enforces additivity checks (base_values + values.sum vs. exact model output), explicit output selection for multi-output models, and background-population documentation. - Visualization guidance: Maps analysis questions to the right plot (bar, beeswarm, waterfall, scatter, heatmap, text, image) with saving and accessibility practices. - Use Case: A data scientist needs to explain a RandomForestClassifier's probability output for a model audit. The Skill walks through interventional TreeExplainer setup, positive-class slicing, additivity assertion, and export of beeswarm and waterfall figures with a metadata record. ## Quick Start Use the shap skill to explain my trained classifier's predictions with a validated TreeExplainer and generate beeswarm and waterfall plots for the test set.

Frequently Asked Questions about shap

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I compute SHAP values for a scikit-learn classifier?▼

Create a shap.Explainer or TreeExplainer with a background sample from training data, then call explainer(X_test) to get a shap.Explanation object. For classifiers, slice one output with explanation[..., class_index] before plotting, and verify base_values plus summed values match predict_proba output.

Which SHAP explainer should I use for my model?▼

Use TreeExplainer for supported tree ensembles like XGBoost, LightGBM, and scikit-learn trees; LinearExplainer for linear models; PermutationExplainer as the general model-agnostic default; and PartitionExplainer for grouped features, text, or images. DeepExplainer or GradientExplainer apply to differentiable TensorFlow and PyTorch models.

What Python version does SHAP 0.52 require?▼

SHAP 0.52.0 requires Python 3.12 or newer and NumPy 2 as a minimum. Projects stuck on Python 3.11 should pin shap 0.51.0, and Python 3.9/3.10 environments can use 0.49.1 as the last compatible release line.

Why does my SHAP waterfall plot fail with a shape error?▼

Waterfall requires a one-dimensional explanation, so multi-output tabular results shaped (samples, features, outputs) must be sliced first. Select the output with explanation[..., class_index], then select the row with explanation[row_index] before calling shap.plots.waterfall.

Can SHAP values prove a model is fair or causal?▼

No. SHAP describes how a model uses features under a chosen background and masking game; it does not establish causality, fairness, or recourse. A protected feature with low attribution does not rule out proxy discrimination, so pair SHAP with performance, calibration, and error-rate analysis.

How do I get probability-space SHAP values for tree models?▼

Instantiate TreeExplainer with model_output="probability", feature_perturbation="interventional", and a background dataset via the data parameter. Probability and log-loss output modes are only supported under interventional semantics in SHAP 0.52.