Scale each feature by its maximum absolute value.
This estimator scales and translates each feature individually such that the maximal absolute value of each feature in the training set will be 1.0. It does not shift/center the data, and thus does not destroy any sparsity.
This scaler can also be applied to sparse CSR or CSC matrices.
.. versionadded:: 0.17
Parameters ---------- copy : boolean, optional, default is True Set to False to perform inplace scaling and avoid a copy (if the input is already a numpy array).
Attributes ---------- scale_ : ndarray, shape (n_features,) Per feature relative scaling of the data.
.. versionadded:: 0.17 *scale_* attribute.
max_abs_ : ndarray, shape (n_features,) Per feature maximum absolute value.
n_samples_seen_ : int The number of samples processed by the estimator. Will be reset on new calls to fit, but increments across ``partial_fit`` calls.
Examples -------- >>> from sklearn.preprocessing import MaxAbsScaler >>> X = [ 1., -1., 2.],
... [ 2., 0., 0.],
... [ 0., 1., -1.]
>>> transformer = MaxAbsScaler().fit(X) >>> transformer MaxAbsScaler() >>> transformer.transform(X) array([ 0.5, -1. , 1. ],
[ 1. , 0. , 0. ],
[ 0. , 1. , -0.5]
)
See also -------- maxabs_scale: Equivalent function without the estimator API.
Notes ----- NaNs are treated as missing values: disregarded in fit, and maintained in transform.
For a comparison of the different scalers, transformers, and normalizers, see :ref:`examples/preprocessing/plot_all_scaling.py <sphx_glr_auto_examples_preprocessing_plot_all_scaling.py>`.