MCPcopy Create free account
hub / github.com/scikit-learn/scikit-learn / maxabs_scale

Function maxabs_scale

sklearn/preprocessing/_data.py:1458–1549  ·  view source on GitHub ↗

Scale each feature to the [-1, 1] range without breaking the sparsity. This estimator scales each feature individually such that the maximal absolute value of each feature in the training set will be 1.0. This scaler can also be applied to sparse CSR or CSC matrices. Parameter

(X, *, axis=0, copy=True)

Source from the content-addressed store, hash-verified

1456 prefer_skip_nested_validation=False,
1457)
1458def maxabs_scale(X, *, axis=0, copy=True):
1459 """Scale each feature to the [-1, 1] range without breaking the sparsity.
1460
1461 This estimator scales each feature individually such
1462 that the maximal absolute value of each feature in the
1463 training set will be 1.0.
1464
1465 This scaler can also be applied to sparse CSR or CSC matrices.
1466
1467 Parameters
1468 ----------
1469 X : {array-like, sparse matrix} of shape (n_samples, n_features)
1470 The data.
1471
1472 axis : {0, 1}, default=0
1473 Axis used to scale along. If 0, independently scale each feature,
1474 otherwise (if 1) scale each sample.
1475
1476 copy : bool, default=True
1477 If False, try to avoid a copy and scale in place.
1478 This is not guaranteed to always work in place; e.g. if the data is
1479 a numpy array with an int dtype, a copy will be returned even with
1480 copy=False.
1481
1482 Returns
1483 -------
1484 X_tr : {ndarray, sparse matrix} of shape (n_samples, n_features)
1485 The transformed data.
1486
1487 .. warning:: Risk of data leak
1488
1489 Do not use :func:`~sklearn.preprocessing.maxabs_scale` unless you know
1490 what you are doing. A common mistake is to apply it to the entire data
1491 *before* splitting into training and test sets. This will bias the
1492 model evaluation because information would have leaked from the test
1493 set to the training set.
1494 In general, we recommend using
1495 :class:`~sklearn.preprocessing.MaxAbsScaler` within a
1496 :ref:`Pipeline <pipeline>` in order to prevent most risks of data
1497 leaking: `pipe = make_pipeline(MaxAbsScaler(), LogisticRegression())`.
1498
1499 See Also
1500 --------
1501 MaxAbsScaler : Performs scaling to the [-1, 1] range using
1502 the Transformer API (e.g. as part of a preprocessing
1503 :class:`~sklearn.pipeline.Pipeline`).
1504
1505 Notes
1506 -----
1507 NaNs are treated as missing values: disregarded to compute the statistics,
1508 and maintained during the data transformation.
1509
1510 For a comparison of the different scalers, transformers, and normalizers,
1511 see: :ref:`sphx_glr_auto_examples_preprocessing_plot_all_scaling.py`.
1512
1513 Examples
1514 --------
1515 >>> from sklearn.preprocessing import maxabs_scale

Calls 3

check_arrayFunction · 0.90
MaxAbsScalerClass · 0.85
fit_transformMethod · 0.45

Tested by 2

test_maxabs_scaler_1dFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…