DeepSHAPExplainer<T>
Models & Types · AiDotNet.Interpretability.Explainers
DeepSHAP explainer combining GradientSHAP with DeepLIFT for efficient neural network explanations.
Implements: IGPUAcceleratedExplainer<T>, IGlobalAttributionExplainer<T>, ILocalExplainer<T, DeepSHAPExplanation<T>>
For Beginners
DeepSHAP is a fast method for computing SHAP values specifically designed for deep neural networks. It combines two powerful ideas:
- DeepLIFT rules: How to properly attribute through non-linearities (ReLU, etc.)
- Shapley sampling: Using multiple baseline samples for better attribution
The key insight is that by using DeepLIFT’s “multipliers” (instead of regular gradients), we get attributions that are more stable and interpretable.
How DeepSHAP works:
- Sample multiple reference inputs from your background data
- For each reference, compute DeepLIFT-style attributions
- Average the attributions across all references
This gives you Shapley-style attributions (fair credit assignment) computed efficiently using backpropagation.
When to use DeepSHAP vs other methods:
- DeepSHAP: Best for deep neural networks, especially with ReLU activations
- GradientSHAP: Simpler, works well when gradients are reliable
- KernelSHAP: Model-agnostic but slower
- IntegratedGradients: Theoretically grounded but uses single baseline
DeepSHAP advantages:
- Fast (single backward pass per sample)
- Handles saturation regions well (via DeepLIFT rules)
- Produces Shapley-like fair attributions
- Works with any differentiable neural network
Constructors
| Constructor | Summary |
|---|---|
DeepSHAPExplainer(Func<Vector<T>, Vector<T>> predictFunction, Func<Vector<T>, int, Vector<T>> gradientFunction, Func<Vector<T>, Vector<T>, Vector<T>> deepLiftMultipliers, Matrix<T> backgroundData, int numSamples, string[] featureNames, int? randomState) |
Initializes a new DeepSHAP explainer with DeepLIFT multiplier support. |
DeepSHAPExplainer(Func<Vector<T>, Vector<T>> predictFunction, Func<Vector<T>, int, Vector<T>> gradientFunction, Matrix<T> backgroundData, int numSamples, string[] featureNames, int? randomState) |
Initializes a new DeepSHAP explainer. |
DeepSHAPExplainer(INeuralNetwork<T> neuralNetwork, Matrix<T> backgroundData, int numSamples, string[] featureNames, int? randomState) |
Initializes a new DeepSHAP explainer from a neural network. |
Properties
| Property | Summary |
|---|---|
T ExpectedValue { get; } |
Gets the expected (baseline) prediction value. |
bool IsGPUAccelerated { get; } |
|
bool SupportsGlobalExplanations { get; } |
|
bool SupportsLocalExplanations { get; } |
|
int NumSamples { get; } |
Gets the number of background samples used for computing attributions. |
string MethodName { get; } |
Methods
| Method | Summary |
|---|---|
DeepSHAPExplanation<T> Explain(Vector<T> instance) |
Computes DeepSHAP attributions for an input. |
DeepSHAPExplanation<T> Explain(Vector<T> instance, int outputIndex) |
Computes DeepSHAP attributions for a specific output. |
DeepSHAPExplanation<T>[] ExplainBatch(Matrix<T> instances) |
|
GlobalDeepSHAPExplanation<T> ExplainGlobal(Matrix<T> data) |
Computes global feature importance by averaging absolute SHAP values. |
Vector<T> ComputeGlobalAttributions(Matrix<T> data) |
|
void SetGPUHelper(GPUExplainerHelper<T> helper) |