SmartExplainerSelector<T>

Models & Types · AiDotNet.Interpretability

Automatically selects the optimal explainer based on model type and provides caching for batch explanations.

For Beginners

Different explanation methods work best for different model types:

Model Type → Best Explainer:

  • Decision Tree → TreeSHAP (exact, fast)
  • Random Forest → TreeSHAP (exact, fast)
  • Gradient Boosting → TreeSHAP (exact, fast)
  • Neural Network → DeepSHAP or Integrated Gradients (uses gradients)
  • Any Model → KernelSHAP or LIME (model-agnostic, slower)

Why auto-selection matters:

  • TreeSHAP is O(TLD²) exact for trees but doesn’t work on neural networks
  • DeepSHAP is fast for neural networks but needs gradient access
  • KernelSHAP works everywhere but is O(2^M) approximation

This class automatically picks the best method for your model type.

Caching: Computing explanations is expensive. This class caches explanations so repeated requests for the same input return instantly.

Constructors

Constructor Summary
SmartExplainerSelector(Func<Matrix<T>, Vector<T>> predictFunction, int numFeatures, ExplainableModelType modelType, string[] featureNames, Matrix<T> backgroundData, SmartExplainerOptions options) Initializes a smart explainer selector with a prediction function.

Properties

Property Summary
ExplainableModelType DetectedModelType { get; } Gets the detected model type.
double CacheHitRate { get; } Gets the cache hit rate.

Methods

Method Summary
ExplainerType GetRecommendedExplainer() Gets the recommended explainer type for the detected model.
FeatureAttribution<T> Explain(Vector<T> instance, int? targetClass) Explains a single instance using the automatically selected method.
FeatureAttribution<T> ExplainWith(Vector<T> instance, ExplainerType explainerType, int? targetClass) Forces use of a specific explainer type.
FeatureAttribution<T>[] ExplainBatch(Matrix<T> instances, int? targetClass) Explains multiple instances in batch.
void ClearCache() Clears the explanation cache.