PermutationFeatureImportance<T>

Models & Types · AiDotNet.Interpretability.Explainers

Model-agnostic Permutation Feature Importance calculator.

Implements: IGPUAcceleratedExplainer<T>, IGlobalExplainer<T, FeatureImportanceResult<T>>

For Beginners

Permutation Feature Importance measures how important each feature is by randomly shuffling that feature’s values and measuring how much worse the model performs.

The intuition is simple:

  • If a feature is important, shuffling it destroys valuable information, and the model performs worse
  • If a feature isn’t important, shuffling it doesn’t matter much

This method works with ANY model because it only looks at the model’s predictions, not its internal structure. It’s like testing which ingredient is most important in a recipe by randomly swapping each ingredient and seeing how much the dish changes.

Constructors

Constructor Summary
PermutationFeatureImportance(Func<Matrix<T>, Vector<T>> predictFunction, Func<Vector<T>, Vector<T>, T> scoreFunction, int nRepeats, string[] featureNames, int? randomState) Initializes a new Permutation Feature Importance calculator.

Properties

Property Summary
bool IsGPUAccelerated { get; }
bool SupportsGlobalExplanations { get; }
bool SupportsLocalExplanations { get; }
string MethodName { get; }

Methods

Method Summary
FeatureImportanceResult<T> Calculate(Matrix<T> X, Vector<T> y) Calculates permutation feature importance.
FeatureImportanceResult<T> ExplainGlobal(Matrix<T> data)
PermutationFeatureImportance<T> ForClassification(IFullModel<T, TInput, TOutput> model, int nRepeats, string[] featureNames, int? randomState) Creates a calculator using accuracy as the scoring function (for classification).
PermutationFeatureImportance<T> ForRegression(IFullModel<T, TInput, TOutput> model, int nRepeats, string[] featureNames, int? randomState) Creates a calculator using R² as the scoring function (for regression).
PermutationFeatureImportance<T> FromModel(IFullModel<T, TInput, TOutput> model, Func<Vector<T>, Vector<T>, T> scoreFunction, int nRepeats, string[] featureNames, int? randomState) Creates a Permutation Feature Importance calculator from a model.
void SetGPUHelper(GPUExplainerHelper<T> helper)