Transform features by scaling each feature to a given range. This estimator scales and translates each feature individually such that it is in the given range on the training set, i.e. between zero and one. The transformation is given by (when ``axis=0``):: X_std = (X - X.
(X, feature_range=(0, 1), *, axis=0, copy=True)
| 629 | prefer_skip_nested_validation=False, |
| 630 | ) |
| 631 | def minmax_scale(X, feature_range=(0, 1), *, axis=0, copy=True): |
| 632 | """Transform features by scaling each feature to a given range. |
| 633 | |
| 634 | This estimator scales and translates each feature individually such |
| 635 | that it is in the given range on the training set, i.e. between |
| 636 | zero and one. |
| 637 | |
| 638 | The transformation is given by (when ``axis=0``):: |
| 639 | |
| 640 | X_std = (X - X.min(axis=0)) / (X.max(axis=0) - X.min(axis=0)) |
| 641 | X_scaled = X_std * (max - min) + min |
| 642 | |
| 643 | where min, max = feature_range. |
| 644 | |
| 645 | The transformation is calculated as (when ``axis=0``):: |
| 646 | |
| 647 | X_scaled = scale * X + min - X.min(axis=0) * scale |
| 648 | where scale = (max - min) / (X.max(axis=0) - X.min(axis=0)) |
| 649 | |
| 650 | This transformation is often used as an alternative to zero mean, |
| 651 | unit variance scaling. |
| 652 | |
| 653 | Read more in the :ref:`User Guide <preprocessing_scaler>`. |
| 654 | |
| 655 | .. versionadded:: 0.17 |
| 656 | *minmax_scale* function interface |
| 657 | to :class:`~sklearn.preprocessing.MinMaxScaler`. |
| 658 | |
| 659 | Parameters |
| 660 | ---------- |
| 661 | X : array-like of shape (n_samples, n_features) |
| 662 | The data. |
| 663 | |
| 664 | feature_range : tuple (min, max), default=(0, 1) |
| 665 | Desired range of transformed data. |
| 666 | |
| 667 | axis : {0, 1}, default=0 |
| 668 | Axis used to scale along. If 0, independently scale each feature, |
| 669 | otherwise (if 1) scale each sample. |
| 670 | |
| 671 | copy : bool, default=True |
| 672 | If False, try to avoid a copy and scale in place. |
| 673 | This is not guaranteed to always work in place; e.g. if the data is |
| 674 | a numpy array with an int dtype, a copy will be returned even with |
| 675 | copy=False. |
| 676 | |
| 677 | Returns |
| 678 | ------- |
| 679 | X_tr : ndarray of shape (n_samples, n_features) |
| 680 | The transformed data. |
| 681 | |
| 682 | .. warning:: Risk of data leak |
| 683 | |
| 684 | Do not use :func:`~sklearn.preprocessing.minmax_scale` unless you know |
| 685 | what you are doing. A common mistake is to apply it to the entire data |
| 686 | *before* splitting into training and test sets. This will bias the |
| 687 | model evaluation because information would have leaked from the test |
| 688 | set to the training set. |
searching dependent graphs…