philsupertramp/game-math
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Private Attributes | List of all members
StandardScaler Class Reference

#include <Scaler.h>

Inheritance diagram for StandardScaler:
Transformer Predictor

Public Member Functions

 StandardScaler (bool withMeans=true, bool withStd=true)
 
void fit (const Matrix< double > &X, const Matrix< double > &y) override
 
Matrix< double > transform (const Matrix< double > &in) override
 
- Public Member Functions inherited from Transformer
Matrix< double > predict (const Matrix< double > &in) override
 
virtual void fit (const Matrix< double > &X, const Matrix< double > &y)=0
 
virtual Matrix< double > predict (const Matrix< double > &)=0
 
virtual Matrix< double > transform (const Matrix< double > &)=0
 

Public Attributes

Matrix< double > means
 
Matrix< double > std_deviations
 

Private Attributes

bool with_std = true
 
bool with_means = true
 

Detailed Description

Standarize features by removing the mean and scaling to unit variance.

The standard score of a sample $x\inX$ with $X\in\mathbf{R}^{N\times M}$ is calculated as $$ \tilde{x} = \frac{x - \mu}{\sigma} $$ with

Note: Standardization of a data set is a common requirement for many ML estimators: They might behave badly if the individual featrues do not more or less look like standard normally distributed data.

For instance many elements used in the objective funtion of a learning algorithm assume that all features are centered around 0 and have variance in the same order. If a feature has a variance that is orders of maginiteds larger than others, it might dominate the objective function and make the estimator unable to learn from other feaztures correctly as expected.[^1]

Examples
ds/preprocessing/TestScaler.cpp.

Constructor & Destructor Documentation

◆ StandardScaler()

StandardScaler::StandardScaler ( bool  withMeans = true,
bool  withStd = true 
)
inline

Member Function Documentation

◆ fit()

void StandardScaler::fit ( const Matrix< double > &  X,
const Matrix< double > &  y 
)
inlineoverridevirtual

Computes mean and sds to be used later in scaling.

Parameters
Xgiven matrix to use to calculate mean/standard deviations
yunused

Implements Predictor.

◆ transform()

Matrix< double > StandardScaler::transform ( const Matrix< double > &  in)
inlineoverridevirtual

Perform standarization by centering and scaling

  • To achieve center at 0 and unit variance.
Parameters
inData to transform
Returns
: transformed data

Implements Predictor.

Member Data Documentation

◆ means

Matrix<double> StandardScaler::means

◆ std_deviations

Matrix<double> StandardScaler::std_deviations

◆ with_means

bool StandardScaler::with_means = true
private

◆ with_std

bool StandardScaler::with_std = true
private

The documentation for this class was generated from the following file: