v0.3.0¶
Release Date: 2025-03-15
Feature release adding KernelSHAP and ExactSHAP explainers, Markdown report generation, and gocharts v2.27.0 upgrade.
New Features¶
KernelSHAP Explainer¶
Model-agnostic SHAP values using weighted linear regression on binary coalition masks.
- Black-box method: Works with any model that returns predictions
- SHAP kernel weights: Uses the mathematically correct kernel
(d-1) / (C(d,k) * k * (d-k)) - Python SHAP validation: Test data validated against Python SHAP library for accuracy
import "github.com/plexusone/shap-go/explainer/kernel"
// Create KernelSHAP explainer
explainer, _ := kernel.New(model, background,
explainer.WithNumSamples(2048),
explainer.WithFeatureNames(featureNames),
)
// Explain a prediction
explanation, _ := explainer.Explain(ctx, instance)
ExactSHAP Explainer¶
Brute-force exact Shapley values by enumerating all 2^n coalitions.
- Mathematically exact: No approximation, guaranteed correct values
- Validation use: Verify other SHAP implementations
- O(n * 2^n) complexity: Only practical for ≤15 features
import "github.com/plexusone/shap-go/explainer/exact"
// Create ExactSHAP explainer (for small feature sets)
explainer, _ := exact.New(model, background,
explainer.WithFeatureNames(featureNames),
)
// Get mathematically exact SHAP values
explanation, _ := explainer.Explain(ctx, instance)
Markdown Report Generation¶
New example for generating Markdown reports with SHAP explanations, useful for documentation and compliance.
New Examples¶
examples/kernelshap/: KernelSHAP weighted linear regression explainerexamples/markdown_report/: Generate Markdown reports with SHAP explanations
Documentation¶
- KernelSHAP guide: Detailed documentation at
docs/explainers/kernelshap.md - Explainers overview: Updated overview with all implemented explainer types
- Internal rand tests: Added comprehensive tests for
internal/randpackage
Dependencies¶
- gocharts v2.27.0: Upgraded from pseudo-version to stable release
- ChartIR refactor: Now uses
gocharts/v2/charts/chartirfor ChartIR types
Bug Fixes¶
- Fix golangci-lint gosec warnings in test files with deterministic seeds
Installation¶
Upgrade Guide¶
- Update import:
go get github.com/plexusone/shap-go@v0.3.0 - Consider using KernelSHAP for model-agnostic explanations as a baseline
- ChartIR types are now from
gocharts/v2/charts/chartirpackage