IInterpretableModel<T>

Interfaces · AiDotNet.Interfaces

Interface for models that support interpretability features.

Known implementations: NeuralNetworkBase<T>, VectorModel<T>

For Beginners

This interface provides a unified way to explain model predictions. Models implementing this interface can use various explanation techniques:

Model-Agnostic Methods (work with any model):

  • SHAP: Shapley value-based feature attribution
  • LIME: Local linear approximations
  • Partial Dependence: Feature effect plots
  • Counterfactual: “What-if” explanations
  • Anchor: Rule-based explanations
  • Feature Importance: Permutation-based importance
  • Feature Interaction: H-statistic for interactions

Neural Network Methods (require gradient access):

  • Integrated Gradients: Path-based attribution
  • DeepLIFT: Activation-based attribution
  • GradCAM: Visual CNN explanations

Enable methods through EnableMethod and configure via InterpretabilityOptions.

Methods

Method Summary
Task<AnchorExplanation<T>> GetAnchorExplanationAsync(Tensor<T> input, T threshold) Gets anchor explanation for a given input.
Task<CounterfactualExplanation<T>> GetCounterfactualAsync(Tensor<T> input, Tensor<T> desiredOutput, int maxChanges) Gets counterfactual explanation for a given input and desired output.
Task<DeepLIFTExplanation<T>> GetDeepLIFTAsync(Tensor<T> input, Tensor<T> baseline, bool useRevealCancel) Gets DeepLIFT attributions for a neural network prediction.
Task<Dictionary<int, T>> GetGlobalFeatureImportanceAsync() Gets the global feature importance across all predictions.
Task<Dictionary<int, T>> GetLocalFeatureImportanceAsync(Tensor<T> input) Gets the local feature importance for a specific input.
Task<Dictionary<string, object>> GetModelSpecificInterpretabilityAsync() Gets model-specific interpretability information.
Task<FairnessMetrics<T>> ValidateFairnessAsync(Tensor<T> inputs, int sensitiveFeatureIndex) Validates fairness metrics for the given inputs.
Task<GradCAMExplanation<T>> GetGradCAMAsync(Tensor<T> input, int targetClass) Gets GradCAM visual explanation for a CNN prediction.
Task<IntegratedGradientsExplanation<T>> GetIntegratedGradientsAsync(Tensor<T> input, Tensor<T> baseline, int numSteps) Gets Integrated Gradients attributions for a neural network prediction.
Task<LimeExplanation<T>> GetLimeExplanationAsync(Tensor<T> input, int numFeatures) Gets LIME explanation for a specific input.
Task<Matrix<T>> GetShapValuesAsync(Tensor<T> inputs) Gets SHAP values for the given inputs.
Task<PartialDependenceData<T>> GetPartialDependenceAsync(Vector<int> featureIndices, int gridResolution) Gets partial dependence data for specified features.
Task<T> GetFeatureInteractionAsync(int feature1Index, int feature2Index) Gets feature interaction effects between two features.
Task<string> GenerateTextExplanationAsync(Tensor<T> input, Tensor<T> prediction) Generates a text explanation for a prediction.
void ConfigureFairness(Vector<int> sensitiveFeatures, FairnessMetric[] fairnessMetrics) Configures fairness evaluation settings.
void EnableMethod(InterpretationMethod[] methods) Enables specific interpretation methods.
void SetBaseModel(IFullModel<T, TInput, TOutput> model) Sets the base model for interpretability analysis.