GradientSHAPExplainer<T>
Models & Types · AiDotNet.Interpretability.Explainers
GradientSHAP explainer - a faster approximation of SHAP using gradients.
Implements: IGPUAcceleratedExplainer<T>, IGlobalAttributionExplainer<T>, ILocalExplainer<T, GradientSHAPExplanation<T>>
For Beginners
GradientSHAP combines ideas from Integrated Gradients and SHAP to create a faster method for explaining neural networks.
How it works:
- Sample random baselines from your background data
- For each baseline, compute something like Integrated Gradients
- Average the results to get SHAP-like values
Comparison with other methods:
- KernelSHAP: Model-agnostic but slow (doesn’t use gradients)
- DeepSHAP: Fast but requires access to layer activations
- GradientSHAP: Good balance - uses gradients but doesn’t need internal model access
Why use GradientSHAP?
- Much faster than KernelSHAP for neural networks
- Only requires gradient computation (not layer access)
- Approximates SHAP values reasonably well
- Better than plain gradients (uses baselines for context)
When to use:
- You have a neural network
- KernelSHAP is too slow
- You don’t have access to model internals (for DeepSHAP)
Constructors
| Constructor | Summary |
|---|---|
GradientSHAPExplainer(Func<Vector<T>, Vector<T>> predictFunction, Func<Vector<T>, int, Vector<T>> gradientFunction, Matrix<T> backgroundData, int numSamples, int numSteps, bool addNoise, double noiseStdDev, string[] featureNames, int? randomState) |
Initializes a new GradientSHAP explainer. |
Properties
| Property | Summary |
|---|---|
bool IsGPUAccelerated { get; } |
|
bool SupportsGlobalExplanations { get; } |
|
bool SupportsLocalExplanations { get; } |
|
string MethodName { get; } |
Methods
| Method | Summary |
|---|---|
GradientSHAPExplanation<T> Explain(Vector<T> instance) |
Computes GradientSHAP attributions for an input. |
GradientSHAPExplanation<T> Explain(Vector<T> instance, int outputIndex) |
Computes GradientSHAP attributions for a specific output. |
GradientSHAPExplanation<T>[] ExplainBatch(Matrix<T> instances) |
|
Vector<T> ComputeGlobalAttributions(Matrix<T> data) |
|
void SetGPUHelper(GPUExplainerHelper<T> helper) |