shap

Compute SHAP values to attribute predictions to features across model types.

3|Updated Oct 26, 2025
One-click install
npx skills add https://github.com/xiechy/climate-ai --skill shap
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: shap
Source: https://github.com/xiechy/climate-ai/tree/main/scientific-packages/shap
Command: npx skills add https://github.com/xiechy/climate-ai --skill shap

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires shap, and includes references (resource) components.

What problem does it solve?

Machine learning models are often "black boxes," making it difficult to understand why they make certain predictions. This skill provides a unified, theoretically sound approach to explain model outputs, enabling users to interpret feature importance, debug model behavior, and ensure fairness.

Core Features & Use Cases

  • Model Interpretability: Compute SHAP values to quantify each feature's contribution to a prediction for any model type (tree-based, deep learning, linear, black-box).
  • Comprehensive Visualizations: Generate various SHAP plots (waterfall, beeswarm, bar, scatter, force, heatmap) to understand global feature importance, individual prediction breakdowns, and feature interactions.
  • Use Case: Debug a credit risk model by generating waterfall plots for rejected loan applications, revealing which specific features (e.g., debt-to-income ratio, credit score) pushed the prediction towards denial.

Quick Start

To explain an XGBoost model, first train your model, then: import shap explainer = shap.TreeExplainer(model) shap_values = explainer(X_test) shap.plots.beeswarm(shap_values)

Frequently Asked Questions about shap

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

FAQPage Schema
How do I explain machine learning model predictions using SHAP values?

SHAP values quantify each feature's contribution to a prediction by computing game-theoretic values. Train your model, initialize a SHAP explainer (TreeExplainer for tree-based models, DeepExplainer for neural networks, KernelExplainer for black-box models), call it on your test data, then visualize results using waterfall, beeswarm, or force plots to see which features pushed predictions in which direction.

Does SHAP work with XGBoost, LightGBM, TensorFlow, and PyTorch models?

Yes. SHAP supports tree-based ensembles (XGBoost, LightGBM, CatBoost, Random Forest), deep learning frameworks (TensorFlow, PyTorch, Keras), linear models, and black-box models through specialized explainers that compute SHAP values efficiently for each architecture.

What are the different SHAP plot types and when should I use each one?

Waterfall plots show how features push individual predictions away from the base value; beeswarm plots reveal global feature importance across all samples; bar charts rank features by average impact; scatter plots explore feature-value relationships; force plots display prediction breakdown compactly; heatmaps show interactions. Choose based on whether you're explaining one prediction or analyzing patterns across many.

Can I use SHAP to debug model bias and fairness issues?

Yes. SHAP values expose which features disproportionately influence predictions, helping identify bias in lending, hiring, or healthcare models. Generate SHAP values across demographic groups and compare feature contributions to spot fairness violations and ensure equitable decision-making.

What data do I need to prepare before computing SHAP values?

You need a trained model and test or evaluation data in the same format the model expects. For TreeExplainer and some explainers, provide background data (a sample of training data) to establish baseline expectations; for model-agnostic explainers like KernelExplainer, background data helps approximate model behavior efficiently.

How do SHAP values help compare and select between different models?

Compute SHAP values for competing models on the same test set, then compare feature importance distributions, interaction patterns, and individual prediction breakdowns. Models with clearer, more consistent feature contributions and fewer spurious interactions typically generalize better and are easier to trust in production.