sklearn.preprocessing
.normalize¶
- sklearn.preprocessing.normalize(X, norm='l2', *, axis=1, copy=True, return_norm=False)[source]¶
Scale input vectors individually to unit norm (vector length).
Read more in the User Guide.
- Parameters:
- X{array-like, sparse matrix} of shape (n_samples, n_features)
The data to normalize, element by element. scipy.sparse matrices should be in CSR format to avoid an un-necessary copy.
- norm{‘l1’, ‘l2’, ‘max’}, default=’l2’
The norm to use to normalize each non zero sample (or each non-zero feature if axis is 0).
- axis{0, 1}, default=1
Define axis used to normalize the data along. If 1, independently normalize each sample, otherwise (if 0) normalize each feature.
- copybool, default=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).
- return_normbool, default=False
Whether to return the computed norms.
- Returns:
- X{ndarray, sparse matrix} of shape (n_samples, n_features)
Normalized input X.
- normsndarray of shape (n_samples, ) if axis=1 else (n_features, )
An array of norms along given axis for X. When X is sparse, a NotImplementedError will be raised for norm ‘l1’ or ‘l2’.
See also
Normalizer
Performs normalization using the Transformer API (e.g. as part of a preprocessing
Pipeline
).
Notes
For a comparison of the different scalers, transformers, and normalizers, see: Compare the effect of different scalers on data with outliers.