Compétence d'explicabilité SHAP

VérifiéPrudence

Compétence d'explicabilité basée sur SHAP pour l'attribution de caractéristiques, graphiques récapitulatifs et analyse d'interactions.

Spar Skills Guide Bot
Data & IAIntermédiaire
67023/07/2026
Claude Code
#shap#explainability#feature-attribution#model-interpretation#ml

Recommandé pour

Synthèse automatique

Calcule des valeurs SHAP pour un modèle entraîné et produit les graphiques d'attribution de features (summary, bar, waterfall, force, dependence, interaction).

Points forts

  • Couvre plusieurs familles d'explainers : TreeExplainer, DeepExplainer, KernelExplainer, linear et gradient
  • Génère un ensemble de graphiques configurable (summary, bar, waterfall, force, dependence, interaction) avec un nombre de features maximal paramétrable
  • Renvoie une sortie structurée : chemin des valeurs SHAP, valeur attendue, classement d'importance des features et interactions principales
  • Prévoit une analyse par cohortes et un échantillonnage (numSamples, backgroundSamples) pour maîtriser le coût de calcul

Limites

  • Suppose que le modèle et les données sont déjà disponibles localement (modelPath, dataPath) : l'entraînement n'est pas pris en charge
  • Ne décrit pas de gestion détaillée des modèles non supportés nativement ni du format exact des fichiers sauvegardés
  • KernelExplainer reste coûteux sur de grands jeux de données, et la qualité des explications dépend du choix des échantillons de background
Quand l'utiliser

À utiliser lorsqu'un modèle entraîné doit être expliqué feature par feature, avec des graphiques prêts à partager pour une revue ou un rapport.

Quand l'éviter

À éviter si vous cherchez à entraîner, tuner ou déployer un modèle, ou s'il vous faut des métriques d'équité avancées que ce skill ne fournit pas.

Analyse de sécurité

Prudence
Score qualité76/100

The skill is a legitimate SHAP explainability specification with no destructive, exfiltrating, or obfuscated instructions. However, it grants Bash and Write permissions and accepts user-supplied filesystem paths, so it can execute code and write files wherever directed. The risk is inherent to a data-science tool rather than malicious, so it merits caution rather than risky.

Points d'attention
  • •Declares Bash and Write access, allowing arbitrary command execution and filesystem writes during skill execution
  • •User-controlled outputDir, modelPath, and dataPath are passed to file I/O without path restrictions, so they could reference sensitive locations
  • •Dependencies (SHAP, matplotlib, numpy) are unpinned, creating supply-chain/version risk
  • •Model deserialization (e.g., .pkl) is implied and can execute arbitrary code if an untrusted model file is supplied
Comment cette analyse est faite

Exemples

Explain an XGBoost model
Use the shap-explainer skill on models/xgboost_model.pkl with data/test.csv, explainerType 'tree', numSamples 1000, backgroundSamples 100, and generate summary, bar and dependence plots into explanations/ with maxFeatures 20.
Model-agnostic explanations
Run shap-explainer with explainerType 'kernel' on my pickled model at artifacts/model.pkl and features at data/holdout.csv; give me the top 15 features by importance and a waterfall plot for the first 5 rows.
Feature interactions analysis
Compute SHAP interaction values for models/lgbm.txt on data/val.csv using TreeExplainer and report the top feature interactions plus a summary plot.

name: shap-explainer description: SHAP-based model explainability skill for feature attribution, summary plots, and interaction analysis. allowed-tools:

  • Read
  • Write
  • Bash
  • Glob
  • Grep graph: domains: [domain:data-science] specializations: [specialization:data-science-ml] skillAreas: [skill-area:explainability-interpretation, skill-area:model-explainability-testing] roles: [role:data-scientist, role:ml-engineer] workflows: [workflow:ml-model-lifecycle]

shap-explainer

Overview

SHAP-based model explainability skill for feature attribution, summary plots, interaction analysis, and model interpretation.

Capabilities

  • TreeExplainer for tree-based models (XGBoost, LightGBM, Random Forest)
  • DeepExplainer for neural networks
  • KernelExplainer for model-agnostic explanations
  • Summary, dependence, and force plots
  • Interaction value computation
  • Cohort-based analysis
  • Waterfall and bar plots
  • Expected value analysis

Target Processes

  • Model Interpretability and Explainability Analysis
  • Model Evaluation and Validation Framework
  • A/B Testing Framework for ML Models

Tools and Libraries

  • SHAP
  • matplotlib
  • numpy

Input Schema

{
  "type": "object",
  "required": ["modelPath", "dataPath", "explainerType"],
  "properties": {
    "modelPath": {
      "type": "string",
      "description": "Path to the trained model"
    },
    "dataPath": {
      "type": "string",
      "description": "Path to data for explanation"
    },
    "explainerType": {
      "type": "string",
      "enum": ["tree", "deep", "kernel", "linear", "gradient"],
      "description": "Type of SHAP explainer to use"
    },
    "analysisConfig": {
      "type": "object",
      "properties": {
        "numSamples": { "type": "integer" },
        "backgroundSamples": { "type": "integer" },
        "featureNames": { "type": "array", "items": { "type": "string" } },
        "outputIndex": { "type": "integer" }
      }
    },
    "plotConfig": {
      "type": "object",
      "properties": {
        "plotTypes": {
          "type": "array",
          "items": { "type": "string", "enum": ["summary", "bar", "waterfall", "force", "dependence", "interaction"] }
        },
        "maxFeatures": { "type": "integer" },
        "outputDir": { "type": "string" }
      }
    }
  }
}

Output Schema

{
  "type": "object",
  "required": ["status", "shapValues"],
  "properties": {
    "status": {
      "type": "string",
      "enum": ["success", "error"]
    },
    "shapValues": {
      "type": "string",
      "description": "Path to SHAP values file"
    },
    "expectedValue": {
      "type": "number"
    },
    "featureImportance": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "feature": { "type": "string" },
          "importance": { "type": "number" },
          "rank": { "type": "integer" }
        }
      }
    },
    "plots": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "type": { "type": "string" },
          "path": { "type": "string" }
        }
      }
    },
    "interactions": {
      "type": "object",
      "description": "Top feature interactions"
    }
  }
}

Usage Example

{
  kind: 'skill',
  title: 'Generate SHAP explanations',
  skill: {
    name: 'shap-explainer',
    context: {
      modelPath: 'models/xgboost_model.pkl',
      dataPath: 'data/test.csv',
      explainerType: 'tree',
      analysisConfig: {
        numSamples: 1000,
        backgroundSamples: 100
      },
      plotConfig: {
        plotTypes: ['summary', 'bar', 'dependence'],
        maxFeatures: 20,
        outputDir: 'explanations/'
      }
    }
  }
}
Skills similaires