SelectFromModel<T>
Models & Types · AiDotNet.Preprocessing.FeatureSelection.Embedded
Selects features based on importance weights from an external model or scorer.
Inheritance: TransformerBase<T, Matrix<T>, Matrix<T>> → SelectFromModel<T>
Implements: ISupervisedFeatureSelector<T>
For Beginners
This works with any model that produces feature importances:
- Random forests give importance based on how much each feature reduces error
- Linear models give coefficients showing feature influence
- Features below the threshold are removed
How It Works
SelectFromModel selects features based on importance scores, typically from a fitted model. Features with importance above a threshold are kept.
The threshold can be specified as:
- An absolute value
- “mean” - the mean of feature importances
- “median” - the median of feature importances
Constructors
| Constructor | Summary |
|---|---|
SelectFromModel(Func<Matrix<T>, Vector<T>, Vector<T>> importanceFunc, SelectFromModelThreshold thresholdType, double thresholdValue, int? maxFeatures, int[] columnIndices) |
Creates a new instance with a function to compute feature importances. |
Properties
| Property | Summary |
|---|---|
T Threshold { get; } |
Gets the computed threshold value. |
Vector<T> FeatureImportances { get; } |
Gets the feature importances used for selection. |
bool SupportsInverseTransform { get; } |
Gets whether this transformer supports inverse transformation. |
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. |
SelectFromModel<T> FromImportances(Vector<T> featureImportances, SelectFromModelThreshold thresholdType, double thresholdValue, int? maxFeatures, int[] columnIndices) |
Creates a new instance with precomputed feature importances. |
bool[] GetSupportMask() |
Gets the support 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 the selector by computing feature importances. |