Загрузка
The data to center and scale.
Axis used to compute the means and standard deviations along. If 0, independently standardize each feature, otherwise (if 1) standardize each sample.
If True, center the data before scaling.
If True, scale the data to unit variance (or equivalently, unit standard deviation).
If False, try to avoid a copy and scale in place. This is not guaranteed to always work in place; e.g. if the data is a numpy array with an int dtype, a copy will be returned even with copy=False.
The transformed data.
This implementation will refuse to center scipy.sparse matrices since it would make them non-sparse and would potentially crash the program with memory exhaustion problems.
Instead the caller is expected to either set explicitly
with_mean=False (in that case, only variance scaling will be
performed on the features of the CSC matrix) or to call X.toarray()
if he/she expects the materialized dense array to fit in memory.
To avoid memory copy the caller should pass a CSC matrix.
NaNs are treated as missing values: disregarded to compute the statistics, and maintained during the data transformation.
We use a biased estimator for the standard deviation, equivalent to
numpy.std(x, ddof=0). Note that the choice of ddof is unlikely to
affect model performance.
For a comparison of the different scalers, transformers, and normalizers, see: Compare the effect of different scalers on data with outliers.
>>> from sklearn.preprocessing import scale
>>> X = [[-2, 1, 2], [-1, 0, 1]]
>>> scale(X, axis=0) # scaling each column independently
array([[-1., 1., 1.],
[ 1., -1., -1.]])
>>> scale(X, axis=1) # scaling each row independently
array([[-1.37, 0.39, 0.98],
[-1.22, 0. , 1.22]])