Chuyển đến nội dung
Skillpedia
Học máy33k · #9029

shap

Skill này làm gì

Skill này cho agent của bạn SHAP, một phương pháp giải thích dự đoán của mô hình. Nó làm việc với mô hình cây, học sâu, mô hình tuyến tính và mô hình hộp đen. Skill dành cho nhà khoa học dữ liệu cần giải thích hoặc gỡ lỗi mô hình.

Khi nào nên dùng

  • ✓Khi bạn cần giải thích những đặc trưng nào tác động nhiều nhất đến dự đoán của mô hình.
  • ✓Khi bạn muốn biểu đồ thác nước, beeswarm hoặc cột thể hiện độ quan trọng đặc trưng.
  • ✓Khi bạn cần kiểm tra mô hình về thiên lệch hoặc hành vi bất ngờ.

Liên kết skill

https://github.com/davila7/claude-code-templates/blob/main/cli-tool/components/skills/scientific/shap/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/davila7/claude-code-templates/blob/main/cli-tool/components/skills/scientific/shap/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Giải thích những đặc trưng nào ảnh hưởng nhiều nhất đến dự đoán của mô hình XGBoost cho vay của tôi, và vẽ biểu đồ beeswarm.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent tính các giá trị SHAP cho mô hình và từng dự đoán. Sau đó nó chuyển chúng thành biểu đồ và bản tóm tắt cho thấy mỗi đặc trưng đẩy dự đoán lên hoặc xuống.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

SHAP (SHapley Additive exPlanations)

Overview

SHAP is a unified approach to explain machine learning model outputs using Shapley values from cooperative game theory. This skill provides comprehensive guidance for:

  • Computing SHAP values for any model type
  • Creating visualizations to understand feature importance
  • Debugging and validating model behavior
  • Analyzing fairness and bias
  • Implementing explainable AI in production

SHAP works with all model types: tree-based models (XGBoost, LightGBM, CatBoost, Random Forest), deep learning models (TensorFlow, PyTorch, Keras), linear models, and black-box models.

When to Use This Skill

Trigger this skill when users ask about:

  • "Explain which features are most important in my model"
  • "Generate SHAP plots" (waterfall, beeswarm, bar, scatter, force, heatmap, etc.)
  • "Why did my model make this prediction?"
  • "Calculate SHAP values for my model"
  • "Visualize feature importance using SHAP"
  • "Debug my model's behavior" or "validate my model"
  • "Check my model for bias" or "analyze fairness"
  • "Compare feature importance across models"
  • "Implement explainable AI" or "add explanations to my model"
  • "Understand feature interactions"
  • "Create model interpretation dashboard"

Quick Start Guide

Step 1: Select the Right Explainer

Decision Tree:

  1. Tree-based model? (XGBoost, LightGBM, CatBoost, Random Forest, Gradient Boosting)

    • Use shap.TreeExplainer (fast, exact)
  2. Deep neural network? (TensorFlow, PyTorch, Keras, CNNs, RNNs, Transformers)

    • Use shap.DeepExplainer or shap.GradientExplainer
  3. Linear model? (Linear/Logistic Regression, GLMs)

    • Use shap.LinearExplainer (extremely fast)
  4. Any other model? (SVMs, custom functions, black-box models)

    • Use shap.KernelExplainer (model-agnostic but slower)
  5. Unsure?

    • Use shap.Explainer (automatically selects best algorithm)

See references/explainers.md for detailed information on all explainer types.

Step 2: Compute SHAP Values

import shap

# Example with tree-based model (XGBoost)
import xgboost as xgb

# Train model
model = xgb.XGBClassifier().fit(X_train, y_train)

# Create explainer
explainer = shap.TreeExplainer(model)

# Compute SHAP values
shap_values = explainer(X_test)

# The shap_values object contains:
# - values: SHAP values (feature attributions)
# - base_values: Expected model output (baseline)
# - data: Original feature values

Step 3: Visualize Results

For Global Understanding (entire dataset):

# Beeswarm plot - shows feature importance with value distributions
shap.plots.beeswarm(shap_values, max_display=15)

# Bar plot - clean summary of feature importance
shap.plots.bar(shap_values)

For Individual Predictions:

# Waterfall plot - detailed breakdown of single prediction
shap.plots.waterfall(shap_values[0])

# Force plot - additive force visualization
shap.plots.force(shap_values[0])

For Feature Relationships:

# Scatter plot - feature-prediction relationship
shap.plots.scatter(shap_values[:, "Feature_Name"])

# Colored by another feature to show interactions
shap.plots.scatter(shap_values[:, "Age"], color=shap_values[:, "Education"])

See references/plots.md for comprehensive guide on all plot types.

Core Workflows

This skill supports several common workflows. Choose the workflow that matches the current task.

Workflow 1: Basic Model Explanation

Goal: Understand what drives model predictions

Steps:

  1. Train model and create appropriate explainer
  2. Compute SHAP values for test set
  3. Generate global importance plots (beeswarm or bar)
  4. Examine top feature relationships (scatter plots)
  5. Explain specific predictions (waterfall plots)

Example:

# Step 1-2: Setup
explainer = shap.TreeExplainer(model)
shap_values = explainer(X_test)

# Step 3: Global importance
shap.plots.beeswarm(shap_values)

# Step 4: Feature relationships
shap.plots.scatter(shap_values[:, "Most_Important_Feature"])

# Step 5: Individual explanation
shap.plots.waterfall(shap_values[0])

Workflow 2: Model Debugging

Goal: Identify and fix model issues

Steps:

  1. Compute SHAP values
  2. Identify prediction errors
  3. Explain misclassified samples
  4. Check for unexpected feature importance (data leakage)
  5. Validate feature relationships make sense
  6. Check feature interactions

**See references/workflows.md for detailed debu

Câu hỏi thường gặp

Giá trị SHAP là gì?

Đó là điểm số cho thấy mỗi đặc trưng đóng góp bao nhiêu vào, hoặc làm giảm, một dự đoán cụ thể, dựa trên giá trị Shapley.

Nó làm việc với những mô hình nào?

Skill bao gồm mô hình cây như XGBoost và LightGBM, mô hình học sâu và mô hình tuyến tính.

Nó có kiểm tra thiên lệch không?

Có. Skill bao gồm phân tích thiên lệch và công bằng của mô hình bằng SHAP.

Chi tiết

Mô tả gốc của tác giả

Model interpretability and explainability using SHAP (SHapley Additive exPlanations). Use this skill when explaining machine learning model predictions, computing feature importance, generating SHAP plots (waterfall, beeswarm, bar, scatter, force, heatmap), debugging models, analyzing model bias or fairness, comparing models, or implementing explainable AI. Works with tree-based models (XGBoost, LightGBM, Random Forest), deep learning (TensorFlow, PyTorch), linear models, and any black-box model.

repo: davila7/claude-code-templates

Độ phổ biến

Sao GitHub
33k
Vị trí xếp hạng
#9029
Giấy phép
MIT
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự