Class SelectPercentile<T>
- Namespace
- AiDotNet.Preprocessing.FeatureSelection
- Assembly
- AiDotNet.dll
Selects features according to a percentile of the highest scores.
public class SelectPercentile<T> : TransformerBase<T, Matrix<T>, Matrix<T>>, IDataTransformer<T, Matrix<T>, Matrix<T>>
Type Parameters
TThe numeric type for calculations (e.g., float, double).
- Inheritance
-
SelectPercentile<T>
- Implements
- Inherited Members
Remarks
SelectPercentile selects the top percentile of features based on a scoring function. For example, selecting the top 10% of features ranked by F-score.
This is similar to SelectKBest but uses a relative threshold (percentile) instead of an absolute number of features.
For Beginners: Instead of specifying an exact number of features: - SelectPercentile(50) keeps the top 50% of features - The actual number depends on your original feature count - Useful when you want a proportion, not an absolute count
Constructors
SelectPercentile(double, SelectKBestScoreFunc, int[]?)
Creates a new instance of SelectPercentile<T>.
public SelectPercentile(double percentile = 10, SelectKBestScoreFunc scoringFunction = SelectKBestScoreFunc.FRegression, int[]? columnIndices = null)
Parameters
percentiledoublePercentile of features to select (0-100). Defaults to 10.
scoringFunctionSelectKBestScoreFuncThe scoring function to use. Defaults to FRegression.
columnIndicesint[]The column indices to evaluate, or null for all columns.
Properties
PValues
Gets the p-values for each feature.
public double[]? PValues { get; }
Property Value
- double[]
Percentile
Gets the percentile of features to select (0-100).
public double Percentile { get; }
Property Value
Scores
Gets the scores for each feature.
public double[]? Scores { get; }
Property Value
- double[]
ScoringFunction
Gets the scoring function used.
public SelectKBestScoreFunc ScoringFunction { get; }
Property Value
SelectedIndices
Gets the indices of selected features.
public int[]? SelectedIndices { get; }
Property Value
- int[]
SupportsInverseTransform
Gets whether this transformer supports inverse transformation.
public override bool SupportsInverseTransform { get; }
Property Value
Methods
Fit(Matrix<T>, Vector<T>)
Fits the selector by computing feature scores.
public void Fit(Matrix<T> data, Vector<T> target)
Parameters
dataMatrix<T>The feature matrix.
targetVector<T>The target values.
FitCore(Matrix<T>)
Fits the selector (requires target via specialized Fit method).
protected override void FitCore(Matrix<T> data)
Parameters
dataMatrix<T>
FitTransform(Matrix<T>, Vector<T>)
Fits and transforms the data.
public Matrix<T> FitTransform(Matrix<T> data, Vector<T> target)
Parameters
dataMatrix<T>targetVector<T>
Returns
- Matrix<T>
GetFeatureNamesOut(string[]?)
Gets the output feature names after transformation.
public override string[] GetFeatureNamesOut(string[]? inputFeatureNames = null)
Parameters
inputFeatureNamesstring[]
Returns
- string[]
GetSupportMask()
Gets the support mask indicating which features are selected.
public bool[] GetSupportMask()
Returns
- bool[]
InverseTransformCore(Matrix<T>)
Inverse transformation is not supported.
protected override Matrix<T> InverseTransformCore(Matrix<T> data)
Parameters
dataMatrix<T>
Returns
- Matrix<T>
TransformCore(Matrix<T>)
Transforms the data by selecting top percentile features.
protected override Matrix<T> TransformCore(Matrix<T> data)
Parameters
dataMatrix<T>
Returns
- Matrix<T>