# MinMaxScaler

### *class* cuml.preprocessing.MinMaxScaler(\*args, \*\*kwargs)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_data.py#L214)

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, e.g. between
zero and one.

The transformation is given by:

```default
X_std = (X - X.min(axis=0)) / (X.max(axis=0) - X.min(axis=0))
X_scaled = X_std * (max - min) + min
```

where min, max = feature_range.

This transformation is often used as an alternative to zero mean,
unit variance scaling.

* **Parameters:**
  **feature_range**
  : Desired range of transformed data.

  **copy**
  : Whether a forced copy will be triggered. If copy=False, a copy might
    be triggered by a conversion.
* **Attributes:**
  **min_**
  : Per feature adjustment for minimum. Equivalent to
    `min - X.min(axis=0) * self.scale_`

  **scale_**
  : Per feature relative scaling of the data. Equivalent to
    `(max - min) / (X.max(axis=0) - X.min(axis=0))`

  **data_min_**
  : Per feature minimum seen in the data

  **data_max_**
  : Per feature maximum seen in the data

  **data_range_**
  : Per feature range `(data_max_ - data_min_)` seen in the data

  **n_samples_seen_**
  : The number of samples processed by the estimator.
    It will be reset on new calls to fit, but increments across
    `partial_fit` calls.

### Methods

| [`fit`](#cuml.preprocessing.MinMaxScaler.fit)(X[, y])          | Compute the minimum and maximum to be used for later scaling.   |
|-----------------------------------------------------------------------|-----------------------------------------------------------------|
| [`inverse_transform`](#cuml.preprocessing.MinMaxScaler.inverse_transform)(X) | Undo the scaling of X according to feature_range.               |
| [`partial_fit`](#cuml.preprocessing.MinMaxScaler.partial_fit)(X[, y])  | Online computation of min and max on X for later scaling.       |
| [`transform`](#cuml.preprocessing.MinMaxScaler.transform)(X)         | Scale features of X according to feature_range.                 |

#### SEE ALSO
[`minmax_scale`](../cuml.preprocessing.minmax_scale/index.html.md#cuml.preprocessing.minmax_scale)
: Equivalent function without the estimator API.

### Notes

NaNs are treated as missing values: disregarded in fit, and maintained in
transform.

### Examples

```pycon
>>> from cuml.preprocessing import MinMaxScaler
>>> import cupy as cp
>>> data = [[-1, 2], [-0.5, 6], [0, 10], [1, 18]]
>>> data = cp.array(data)
>>> scaler = MinMaxScaler()
>>> print(scaler.fit(data))
MinMaxScaler()
>>> print(scaler.data_max_)
[ 1. 18.]
>>> print(scaler.transform(data))
[[0.   0.  ]
 [0.25 0.25]
 [0.5  0.5 ]
 [1.   1.  ]]
>>> print(scaler.transform(cp.array([[2, 2]])))
[[1.5 0. ]]
```

<!-- !! processed by numpydoc !! -->

#### fit(X, y=None) → [MinMaxScaler](#cuml.preprocessing.MinMaxScaler)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_data.py#L332)

Compute the minimum and maximum to be used for later scaling.

* **Parameters:**
  **X**
  : The data used to compute the per-feature minimum and maximum
    used for later scaling along the features axis.

  **y**
  : Ignored.
* **Returns:**
  **self**
  : Fitted scaler.

<!-- !! processed by numpydoc !! -->

#### fit_transform(X, y=None, \*\*fit_params)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/utils/skl_dependencies.py#L42)

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit_params
and returns a transformed version of X.

* **Parameters:**
  **X**

  **y**
  : Target values.

  **\*\*fit_params**
  : Additional fit parameters.
* **Returns:**
  **X_new**
  : Transformed array.

<!-- !! processed by numpydoc !! -->

#### get_feature_names_out(input_features=None)

Get output feature names for transformation.

* **Parameters:**
  **input_features**
  : Input features.
    - If `input_features` is [`None`](https://docs.python.org/3/builtins/constants.html#None), then `feature_names_in_` is
      used as feature names in. If `feature_names_in_` is not defined,
      then the following input feature names are generated:
      `["x0", "x1", ..., "x(n_features_in_ - 1)"]`.
    - If `input_features` is an array-like, then `input_features` must
      match `feature_names_in_` if `feature_names_in_` is defined.
* **Returns:**
  **feature_names_out**
  : Same as input features.

<!-- !! processed by numpydoc !! -->

#### get_params(deep=True)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/internals/base.py#L191)

Returns a dict of all params owned by this class. If the child class
has appropriately overridden the `_get_param_names` method and does not
need anything other than what is there in this method, then it doesn’t
have to override this method

<!-- !! processed by numpydoc !! -->

#### inverse_transform(X)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_data.py#L437)

Undo the scaling of X according to feature_range.

* **Parameters:**
  **X**
  : Input data that will be transformed. It cannot be sparse.
* **Returns:**
  **Xt**
  : Transformed data.

<!-- !! processed by numpydoc !! -->

#### partial_fit(X, y=None) → [MinMaxScaler](#cuml.preprocessing.MinMaxScaler)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_data.py#L355)

Online computation of min and max on X for later scaling.

All of X is processed as a single batch. This is intended for cases
when [`fit()`](#cuml.preprocessing.MinMaxScaler.fit) is not feasible due to very large number of
`n_samples` or because X is read from a continuous stream.

* **Parameters:**
  **X**
  : The data used to compute the mean and standard deviation
    used for later scaling along the features axis.

  **y**
  : Ignored.
* **Returns:**
  **self**
  : Transformer instance.

<!-- !! processed by numpydoc !! -->

#### set_params(\*\*params)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/internals/base.py#L200)

Accepts a dict of params and updates the corresponding ones owned by
this class. If the child class has appropriately overridden the
`_get_param_names` method and does not need anything other than what is,
there in this method, then it doesn’t have to override this method

<!-- !! processed by numpydoc !! -->

#### transform(X)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_data.py#L410)

Scale features of X according to feature_range.

* **Parameters:**
  **X**
  : Input data that will be transformed.
* **Returns:**
  **Xt**
  : Transformed data.

<!-- !! processed by numpydoc !! -->
