SHAPExplainer<T>
Models & Types · AiDotNet.Interpretability.Explainers
Model-agnostic SHAP (SHapley Additive exPlanations) explainer using Kernel SHAP algorithm.
Implements: IGPUAcceleratedExplainer<T>, IGlobalExplainer<T, GlobalSHAPExplanation<T>>, ILocalExplainer<T, SHAPExplanation<T>>
For Beginners
SHAP values come from game theory and answer the question: “How much did each feature contribute to this specific prediction?”
Imagine you’re splitting a restaurant bill fairly among friends based on what each person ordered. SHAP does something similar - it fairly distributes the “credit” for a prediction among all input features.
Key properties of SHAP values:
- They sum up to the difference between the prediction and the average prediction
- Positive values mean the feature pushed the prediction higher
- Negative values mean the feature pushed the prediction lower
- The magnitude shows how important that feature was
This implementation uses Kernel SHAP, which works with ANY model by treating it as a black box.
Constructors
| Constructor | Summary |
|---|---|
SHAPExplainer(Func<Matrix<T>, Vector<T>> predictFunction, Matrix<T> backgroundData, int nSamples, string[] featureNames, int? randomState) |
Initializes a new SHAP explainer with a prediction function and background data. |
Properties
| Property | Summary |
|---|---|
T BaselineValue { get; } |
Gets the baseline (expected) prediction value computed from background data. |
bool IsGPUAccelerated { get; } |
|
bool SupportsGlobalExplanations { get; } |
|
bool SupportsLocalExplanations { get; } |
|
int NumFeatures { get; } |
Gets the number of features being explained. |
string MethodName { get; } |
Methods
| Method | Summary |
|---|---|
GlobalSHAPExplanation<T> ExplainGlobal(Matrix<T> data) |
|
SHAPExplainer<T> FromModel(IFullModel<T, TInput, TOutput> model, Matrix<T> backgroundData, int nSamples, string[] featureNames, int? randomState) |
Initializes a new SHAP explainer with a model that implements prediction. |
SHAPExplanation<T> Explain(Vector<T> instance) |
|
SHAPExplanation<T>[] ExplainBatch(Matrix<T> instances) |
|
void SetGPUHelper(GPUExplainerHelper<T> helper) |