LIMESelector<T>

Models & Types · AiDotNet.Preprocessing.FeatureSelection.ModelAgnostic

LIME (Local Interpretable Model-agnostic Explanations) based feature selection.

Inheritance: TransformerBase<T, Matrix<T>, Matrix<T>> → LIMESelector<T>

Implements: IFixedCountFeatureSelector<T>, ISupervisedFeatureSelector<T>

For Beginners

LIME answers: “For this specific prediction, which features mattered most?”

It works by creating slightly modified versions of your data point, seeing how predictions change, and fitting a simple linear model to understand which features drive the prediction locally.

Unlike global methods, LIME provides instance-specific explanations. For feature selection, we average importance across many instances.

How It Works

LIME explains individual predictions by approximating the model locally with an interpretable linear model. Feature importance is derived from the linear coefficients of these local explanations.

The algorithm:

  1. For each instance to explain:

a. Generate perturbed samples around the instance b. Weight samples by proximity to original instance c. Fit weighted linear regression on perturbed samples d. Extract feature importance from coefficients

  1. Aggregate importance across all explained instances

Constructors

Constructor Summary
LIMESelector(Func<Matrix<T>, Vector<T>> predictFunc, int nFeaturesToSelect, int nSamplesToExplain, int nPerturbations, double kernelWidth, int? randomState, int[] columnIndices) Creates a new instance of LIMESelector.

Properties

Property Summary
Vector<T> Importances { get; } Gets the computed LIME importance values (mean absolute coefficients).
bool SupportsInverseTransform { get; } Gets whether this transformer supports inverse transformation.
int NFeaturesToSelect { get; } Gets the number of features to select.
int[] SelectedIndices { get; } Gets the indices of selected features.

Methods

Method Summary
Matrix<T> FitTransform(Matrix<T> data, Vector<T> target) Fits and transforms the data.
bool[] GetSupportMask() Gets a boolean mask indicating which features are selected.
string[] GetFeatureNamesOut(string[] inputFeatureNames) Gets the output feature names after transformation.
void Fit(Matrix<T> data, Vector<T> target) Fits LIME selector by computing local explanations and aggregating importance.