shap-explainerSkill shap-explainer

SHAP模型可解释性技能,用于机器学习模型的特征重要性分析、可视化解释和交互效应评估。提供SHAP值计算、特征归因、汇总图、依赖图、力图、瀑布图等多种分析功能,支持树模型、神经网络和通用模型的解释,帮助数据科学家和AI工程师理解模型决策、验证模型效果并进行模型调试。关键词:SHAP,模型可解释性,特征重要性,机器学习解释,AI模型分析,XAI,特征归因,可视化分析。

机器学习 1 次安装 2 次浏览 更新于 2/23/2026

名称: shap-explainer 描述: 基于SHAP的模型可解释性技能,用于特征归因、汇总图、交互分析和模型解释。 允许的工具:

  • 读取
  • 写入
  • Bash
  • Glob
  • Grep

shap-explainer

概述

基于SHAP的模型可解释性技能,用于特征归因、汇总图、交互分析和模型解释。

能力

  • 用于树模型的TreeExplainer(XGBoost、LightGBM、随机森林)
  • 用于神经网络的DeepExplainer
  • 用于模型无关解释的KernelExplainer
  • 汇总图、依赖图和力图
  • 交互值计算
  • 基于队列的分析
  • 瀑布图和条形图
  • 期望值分析

目标流程

  • 模型可解释性与可解释性分析
  • 模型评估与验证框架
  • 机器学习模型的A/B测试框架

工具与库

  • SHAP
  • matplotlib
  • numpy

输入模式

{
  "type": "object",
  "required": ["modelPath", "dataPath", "explainerType"],
  "properties": {
    "modelPath": {
      "type": "string",
      "description": "训练模型的路径"
    },
    "dataPath": {
      "type": "string",
      "description": "用于解释的数据路径"
    },
    "explainerType": {
      "type": "string",
      "enum": ["tree", "deep", "kernel", "linear", "gradient"],
      "description": "要使用的SHAP解释器类型"
    },
    "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" }
      }
    }
  }
}

输出模式

{
  "type": "object",
  "required": ["status", "shapValues"],
  "properties": {
    "status": {
      "type": "string",
      "enum": ["success", "error"]
    },
    "shapValues": {
      "type": "string",
      "description": "SHAP值文件的路径"
    },
    "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": "顶级特征交互"
    }
  }
}

使用示例

{
  kind: 'skill',
  title: '生成SHAP解释',
  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/'
      }
    }
  }
}