sciagent-skill-creator
Scaffold a new SciAgent-Skills entry. Picks pipeline/toolkit/database/guide template, creates skills/{category}/{name}/SKILL.md with valid frontmatter, appends…
Model interpretability via SHAP (Shapley values from game theory). Covers explainer choice (Tree, Deep, Linear, Kernel, Gradient, Permutation), feature attribution, and plots (waterfall, beeswarm, bar, scatter, force, heatmap). Use to explain ML predictions, rank features, debug
$ npx -y skills add jaechang-hits/SciAgent-Skills --skill shap-model-explainability --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/shap-model-explainabilityContext preview
The summary Claude sees to decide when to auto-load this skill.
Model interpretability via SHAP (Shapley values from game theory). Covers explainer choice (Tree, Deep, Linear, Kernel, Gradient, Permutation), feature attribution, and plots (waterfall, beeswarm, bar, scatter, force, heatmap). Use to explain ML predictions, rank features, debug
name: shap-model-explainability description: >- Model interpretability via SHAP (Shapley values from game theory). Covers explainer choice (Tree, Deep, Linear, Kernel, Gradient, Permutation), feature attribution, and plots (waterfall, beeswarm, bar, scatter, force, heatmap). Use to explain ML predictions, rank features, debug models, audit fairness, or compare models. Works with tree, deep, linear, and black-box models. license: MIT
SHAP (SHapley Additive exPlanations) is a unified framework for explaining machine learning model predictions using Shapley values from cooperative game theory. It quantifies each feature's contribution to individual predictions and provides both local (per-instance) and global (dataset-level) explanations with theoretical guarantees of consistency and additivity.
pip install shap matplotlib # Optional: xgboost lightgbm tensorflow torch (depending on model)
import shap
import xgboost as xgb
from sklearn.model_selection import train_test_split
# Load example data
X, y = shap.datasets.adult()
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
# Train model
model = xgb.XGBClassifier(n_estimators=100).fit(X_train, y_train)
# Explain: select explainer → compute → visualize
explainer = shap.TreeExplainer(model)
shap_values = explainer(X_test)
shap.plots.beeswarm(shap_values) # Global importance
shap.plots.waterfall(shap_values[0]) # Single prediction
print(f"Base value: {shap_values.base_values[0]:.3f}")
print(f"SHAP values shape: {shap_values.values.shape}") # (n_samples, n_features)Choose based on model type:
| Model Type | Explainer | Speed | Exactness | |-----------|-----------|-------|-----------| | Tree-based (XGBoost, LightGBM, RF, CatBoost) | `TreeExplainer` | Fast | Exact | | Linear (LogReg, GLM, Ridge) | `LinearExplainer` | Instant | Exact | | Deep learning (TensorFlow, PyTorch) | `DeepExplainer` | Fast | Approximate | | Deep learning (gradient-based) | `GradientExplainer` | Fast | Approximate | | Any model (black-box) | `KernelExplainer` | Slow | Approximate | | Any model (permutation-based) | `PermutationExplainer` | Very slow | Exact | | **Unsure?** | `shap.Explainer` | Auto | Auto |
# Tree-based models (most common) explainer = shap.TreeExplainer(model) # Linear models explainer = shap.LinearExplainer(model, X_train) # Deep learning explainer = shap.DeepExplainer(model, X_train[:100]) # Any model (model-agnostic, slower) explainer = shap.KernelExplainer(model.predict, shap.kmeans(X_train, 50)) # Auto-select explainer = shap.Explainer(model, X_train)
shap_values = explainer(X_test)
# shap_values object contains:
# .values — SHAP values array (n_samples, n_features)
# .base_values — Expected model output (baseline)
# .data — Original feature values
# Verify additivity: prediction = base_value + sum(SHAP values)
print(f" {shap_values.base_values[0]:.3f} + {shap_values.values[0].sum():.3f} = "
f"{shap_values.base_values[0] + shap_values.values[0].sum():.3f}")# Beeswarm: feature importance + value distributions (most informative) shap.plots.beeswarm(shap_values, max_display=15) # Bar: clean mean |SHAP| importance shap.plots.bar(shap_values)
# Waterfall: detailed breakdown of one prediction shap.plots.waterfall(shap_values[0]) # Force: additive force visualization shap.plots.force(shap_values[0])
# Scatter: how a feature affects predictions shap.plots.scatter(shap_values[:, "Age"]) # Colored by interaction feature shap.plots.scatter(shap_values[:, "Age"], color=shap_values[:, "Education-Num"])
# Heatmap: multi-sample SHAP grid
shap.plots.heatmap(shap_values[:100])
# Decision plot: cumulative SHAP paths
shap.plots.decision(shap_values.base_values[0], shap_values.values[:10],
feature_names=X_test.columns.tolist())
# Cohort comparison
import numpy as np
mask_a = X_test["Age"] < 40
shap.plots.bar({
"Under 40": shap_values[mask_a],
"40+": shap_values[~mask_a]
})| Parameter | Explainer/Function | Default | Effect | |-----------|-------------------|---------|--------| | `feature_perturbation` | TreeExplainer | `"tree_path_dependent"` | `"interventional"` for causal interpretation (requires background data) | | `model_output` | TreeExplainer | `"raw"` | `"probability"` to explain probabilities instead of log-odds | | `data` (background) | KernelExplainer, DeepExplainer | Required | 100-1000 representative samples; use `shap.kmeans(X, 50)` for efficiency | | `nsamples` | KernelExplainer | `"auto"` | Higher = more accurate but slower; minimum 2×features | | `max_display` | All plot functions | 10 | Number of features shown in plots | | `alpha` | scatter/beeswarm | 1.0 | Point transparency for dense datasets | | `show` | All plot functions | True | Set `False` to get matplotlib figure for saving | | `clustering` | beeswarm | None | `shap.utils.hclust(...)` to cluster correlated features |
Turn your AI coding agent into a life sciences expert — 199 bioinformatics skills for Claude Code covering RNA-seq, single-cell analysis, genomics, proteomics, drug discovery, and more. Boosted BixBench from 65% to 92%. Open source.
Scaffold a new SciAgent-Skills entry. Picks pipeline/toolkit/database/guide template, creates skills/{category}/{name}/SKILL.md with valid frontmatter, appends…
Bayesian modeling with PyMC 5: priors, likelihood, NUTS/ADVI sampling, diagnostics (R-hat, ESS), LOO/WAIC comparison, prediction. Hierarchical, logistic, GP…
Time-to-event modeling with scikit-survival: Cox PH (elastic net), Random Survival Forests, Boosting, SVMs for censored data. C-index, Brier, time-dependent…
Guided statistical analysis: test choice, assumption checks, effect sizes, power, APA reporting. Pick tests, verify assumptions, or format results for…
Python statistical modeling: regression (OLS, WLS, GLM), discrete (Logit, Poisson, NegBin), time series (ARIMA, SARIMAX, VAR), with rigorous inference,…
DL cell/nucleus segmentation for fluorescence and brightfield microscopy. Pre-trained models (cyto3, nuclei, tissuenet) and a generalist flow-based algorithm…