shap

Compute SHAP values and generate explanation plots for machine learning models.

Updated Oct 7, 2022
One-click install
npx skills add https://github.com/tamagusko/linux-cfg --skill shap-tamagusko
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: shap
Source: https://github.com/tamagusko/linux-cfg/tree/main/dotfiles/claude/skills/shap
Command: npx skills add https://github.com/tamagusko/linux-cfg --skill shap-tamagusko

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Machine learning models act as black boxes, making it hard to understand why they produce specific predictions, debug errors, detect bias, or justify decisions to stakeholders. This Skill provides structured guidance for explaining model predictions using SHAP (SHapley Additive exPlanations), from choosing the right explainer to producing publication-ready visualizations. ## Core Features & Use Cases - Explainer Selection: Decision guidance for TreeExplainer, DeepExplainer, KernelExplainer, LinearExplainer, GradientExplainer, and PermutationExplainer across XGBoost, LightGBM, TensorFlow, PyTorch, and scikit-learn models. - Visualization Workflows: Instructions for waterfall, beeswarm, bar, scatter, force, heatmap, violin, and decision plots for both global feature importance and individual prediction breakdowns. - Advanced Workflows: Step-by-step processes for model debugging, feature engineering, fairness and bias analysis, model comparison, and production deployment of explanation services. - Use Case: After training an XGBoost classifier, compute SHAP values with TreeExplainer, generate a beeswarm plot to rank global feature importance, then use waterfall plots to explain individual misclassified predictions and check for data leakage. ## Quick Start Explain my trained XGBoost model's predictions using SHAP and show me the most important features with a beeswarm plot.

Frequently Asked Questions about shap

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

FAQPage Schema
How do I explain model predictions with SHAP in Python?

Create an explainer matching your model type, such as shap.TreeExplainer for XGBoost or Random Forest, then call it on your test data to get SHAP values. Visualize results with shap.plots.beeswarm for global importance or shap.plots.waterfall for individual predictions.

Which SHAP explainer should I use for my model?

Use TreeExplainer for tree-based models like XGBoost, LightGBM, and Random Forest; DeepExplainer or GradientExplainer for TensorFlow and PyTorch networks; LinearExplainer for linear models; and KernelExplainer only for black-box models without a specialized option.

Does SHAP work with deep learning models like PyTorch and TensorFlow?

Yes, DeepExplainer and GradientExplainer support TensorFlow, Keras, and PyTorch models. Provide 100-1000 background samples from training data to balance explanation accuracy against computation time.

Why are my SHAP values in log-odds instead of probabilities?

XGBoost classifiers explain margin output (log-odds) by default rather than probabilities. Pass model_output="probability" to TreeExplainer to explain probability-transformed outputs instead.

How do I speed up slow SHAP value computation?

Use specialized explainers like TreeExplainer instead of KernelExplainer, compute SHAP values on a data subset, or process large datasets in batches. KernelExplainer and PermutationExplainer are significantly slower than model-specific alternatives.

Can SHAP values prove a feature causes a prediction?

No, SHAP measures association between features and model output, not causation. It shows how the model uses each feature, so causal interpretation requires domain knowledge and cannot be derived from SHAP values alone.