SelectKBest<T>
Models & Types ยท AiDotNet.Preprocessing.FeatureSelection.Filter.Univariate
Selects the K highest-scoring features according to a scoring function.
Inheritance: TransformerBase<T, Matrix<T>, Matrix<T>> โ SelectKBest<T>
For Beginners
Not all features are equally useful for prediction. SelectKBest helps you:
- Reduce the number of features to improve model speed
- Remove noisy features that might hurt model accuracy
- Find the most informative features for understanding your problem
Example: From 100 features, select the 10 most related to your target.
How It Works
SelectKBest computes a score for each feature based on the relationship between the feature and the target variable, then selects the top K features with the highest scores.
Built-in scoring functions include:
- F-score for regression (linear relationship)
- Mutual information (any relationship type)
Constructors
| Constructor | Summary |
|---|---|
SelectKBest(int k, SelectKBestScoreFunc scoreFunc, int[] columnIndices) |
Creates a new instance of SelectKBest. |
Properties
| Property | Summary |
|---|---|
SelectKBestScoreFunc ScoreFunc { get; } |
Gets the scoring function used. |
Vector<T> PValues { get; } |
Gets the p-values for each feature, or null when the scoring function has none (mutual information). |
Vector<T> Scores { get; } |
Gets the computed scores for each feature. |
bool SupportsInverseTransform { get; } |
Gets whether this transformer supports inverse transformation. |
int K { get; } |
Gets the number of features to select. |
int[] SelectedFeatures { get; } |
Gets the indices of selected features. |
Methods
| Method | Summary |
|---|---|
Matrix<T> FitTransform(Matrix<T> data, Vector<T> target) |
Fits the selector and transforms the data in one step. |
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 the selector by computing feature scores based on the target. |