Class StandardScaler<T>
- Namespace
- AiDotNet.Preprocessing.Scalers
- Assembly
- AiDotNet.dll
Standardizes features by removing the mean and scaling to unit variance.
public class StandardScaler<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
-
StandardScaler<T>
- Implements
- Inherited Members
Remarks
Standard scaling (Z-score normalization) transforms data to have a mean of 0 and a standard deviation of 1. This is important for many machine learning algorithms as it puts different features on comparable scales.
For Beginners: This scaler converts your data to a standard scale: - The center of your data (mean) becomes 0 - The spread of your data (standard deviation) becomes 1
This is like converting different currencies to a common one - it makes different features comparable and helps many ML algorithms work better.
Constructors
StandardScaler(bool, bool, int[]?)
Creates a new instance of StandardScaler<T>.
public StandardScaler(bool withMean = true, bool withStd = true, int[]? columnIndices = null)
Parameters
withMeanboolIf true, center the data before scaling (subtract mean). Default is true.
withStdboolIf true, scale the data to unit variance. Default is true.
columnIndicesint[]The column indices to scale, or null for all columns.
Properties
Mean
Gets the mean of each feature computed during fitting.
public Vector<T>? Mean { get; }
Property Value
- Vector<T>
StandardDeviation
Gets the standard deviation of each feature computed during fitting.
public Vector<T>? StandardDeviation { get; }
Property Value
- Vector<T>
SupportsInverseTransform
Gets whether this transformer supports inverse transformation.
public override bool SupportsInverseTransform { get; }
Property Value
WithMean
Gets whether this scaler centers the data (subtracts mean).
public bool WithMean { get; }
Property Value
WithStd
Gets whether this scaler scales the data (divides by std).
public bool WithStd { get; }
Property Value
Methods
FitCore(Matrix<T>)
Computes the mean and standard deviation of each feature from the training data.
protected override void FitCore(Matrix<T> data)
Parameters
dataMatrix<T>The training data matrix where each column is a feature.
GetFeatureNamesOut(string[]?)
Gets the output feature names after transformation.
public override string[] GetFeatureNamesOut(string[]? inputFeatureNames = null)
Parameters
inputFeatureNamesstring[]The input feature names.
Returns
- string[]
The same feature names (StandardScaler doesn't change number of features).
InverseTransformCore(Matrix<T>)
Reverses the standardization transformation.
protected override Matrix<T> InverseTransformCore(Matrix<T> data)
Parameters
dataMatrix<T>The standardized data.
Returns
- Matrix<T>
The original-scale data.
TransformCore(Matrix<T>)
Transforms the data by applying the computed mean and standard deviation.
protected override Matrix<T> TransformCore(Matrix<T> data)
Parameters
dataMatrix<T>The data to transform.
Returns
- Matrix<T>
The standardized data.