Skip to contents

The standard score of a sample x is calculated as: $$z = \frac{(x - u)}{s}$$ where \(u\) is the mean of the training samples or 0 if with_mean = FALSE, and \(s\) is the standard deviation of the training samples or 1 if with_std = FALSE.

Standardization of a dataset is a common requirement for many machine learning estimators: they might behave badly if the individual features do not more or less look like standard normally distributed data (e.g. Gaussian with 0 mean and unit variance).

For instance many elements used in the objective function of a learning algorithm (such as the RBF kernel of Support Vector Machines or the L1 and L2 regularizers of linear models) 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 magnitude larger than others, it might dominate the objective function and make the estimator unable to learn from other features correctly as expected.

This scaler can also be applied to sparse CSR or CSC matrices by passing with_mean = FALSE to avoid breaking the sparsity structure of the data.

Super classes

rgudhi::PythonClass -> rgudhi::SKLearnClass -> rgudhi::BaseScaler -> StandardScaler

Methods

Inherited methods


Method new()

The StandardScaler class constructor.

Usage

StandardScaler$new(copy = TRUE, with_mean = TRUE, with_std = TRUE)

Arguments

copy

A boolean value specifying whether to perform in-place scaling and avoid a copy (if the input is already a numpy array). Defaults to TRUE.

with_mean

A boolean value specifying whether to center the data before scaling. This does not work (and will raise an exception) when attempted on sparse matrices, because centering them entails building a dense matrix which in common use cases is likely to be too large to fit in memory. Defaults to TRUE.

with_std

A boolean value specifying whether to scale the data to unit variance (or equivalently, unit standard deviation). Defaults to TRUE.

Returns

An object of class StandardScaler.


Method clone()

The objects of this class are cloneable with this method.

Usage

StandardScaler$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

if (FALSE) { # reticulate::py_module_available("sklearn.preprocessing")
ss <- StandardScaler$new()
}