This documentation is for scikit-learn version 0.11-gitOther versions

Citing

If you use the software, please consider citing scikit-learn.

This page

8.24.1. sklearn.preprocessing.Scaler

class sklearn.preprocessing.Scaler(copy=True, with_mean=True, with_std=True)

Standardize features by removing the mean and scaling to unit variance

Centering and scaling happen indepently on each feature by computing the relevant statistics on the samples in the training set. Mean and standard deviation are then stored to be used on later data using the transform method.

Standardization of a dataset is a common requirement for many machine learning estimators: they might behave badly if the individual feature 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 that others, it might dominate the objective function and make the estimator unable to learn from other features correctly as expected.

Parameters :

with_mean : boolean, True by default

If True, center the data before scaling.

with_std : boolean, True by default

If True, scale the data to unit variance (or equivalently, unit standard deviation).

copy : boolean, optional, default is True

set to False to perform inplace row normalization and avoid a copy (if the input is already a numpy array or a scipy.sparse CSR matrix and if axis is 1).

Attributes

mean_ array of floats with shape [n_features] The mean value for each feature in the training set.
std_ array of floats with shape [n_features] The standard deviation for each feature in the training set.

Methods

fit(X[, y]) Compute the mean and std to be used for later scaling
fit_transform(X[, y]) Fit to data, then transform it
get_params([deep]) Get parameters for the estimator
inverse_transform(X[, copy]) Scale back the data to the original representation
set_params(**params) Set the parameters of the estimator.
transform(X[, y, copy]) Perform standardization by centering and scaling
__init__(copy=True, with_mean=True, with_std=True)
fit(X, y=None)

Compute the mean and std to be used for later scaling

Parameters :

X : array-like or CSR matrix with shape [n_samples, n_features]

The data used to compute the mean and standard deviation used for later scaling along the features axis.

fit_transform(X, y=None, **fit_params)

Fit to data, then transform it

Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.

Parameters :

X : numpy array of shape [n_samples, n_features]

Training set.

y : numpy array of shape [n_samples]

Target values.

Returns :

X_new : numpy array of shape [n_samples, n_features_new]

Transformed array.

Notes

This method just calls fit and transform consecutively, i.e., it is not an optimized implementation of fit_transform, unlike other transformers such as PCA.

get_params(deep=True)

Get parameters for the estimator

Parameters :

deep: boolean, optional :

If True, will return the parameters for this estimator and contained subobjects that are estimators.

inverse_transform(X, copy=None)

Scale back the data to the original representation

Parameters :

X : array-like with shape [n_samples, n_features]

The data used to scale along the features axis.

set_params(**params)

Set the parameters of the estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The former have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Returns :self :
transform(X, y=None, copy=None)

Perform standardization by centering and scaling

Parameters :

X : array-like with shape [n_samples, n_features]

The data used to scale along the features axis.