preprocessing.MinMaxScaler

Transforms 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:

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.

Usage

import { MinMaxScaler } from 'machinelearn/preprocessing';

const minmaxScaler = new MinMaxScaler({ featureRange: [0, 1] });

// Fitting an 1D matrix
minmaxScaler.fit([4, 5, 6]);
const result = minmaxScaler.transform([4, 5, 6]);
// result = [ 0, 0.5, 1 ]

// Fitting a 2D matrix
const minmaxScaler2 = new MinMaxScaler({ featureRange: [0, 1] });
minmaxScaler2.fit([[1, 2, 3], [4, 5, 6]]);
const result2 = minmaxScaler2.transform([[1, 2, 3]]);
// result2 = [ [ 0, 0.2, 0.4000000000000001 ] ]

Constructors

Methods

Constructors


constructor

new MinMaxScaler(__namedParameters: `object`)

Defined in preprocessing/data.ts:410

Parameters:

ParamTypeDefaultDescription
options.featureRangenumber[][0, 1]scaling range

Returns: MinMaxScaler

Methods


λ fit

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

Defined in preprocessing/data.ts:431

Parameters:

ParamTypeDefaultDescription
Xnumber[] or number[][]nullArray or sparse-matrix data input

Returns:

void

λ fit_transform

Fit to data, then transform it.

Defined in preprocessing/data.ts:459

Parameters:

ParamTypeDefaultDescription
Xnumber[] or number[][]Original input vector

Returns:

λ inverse_transform

Undo the scaling of X according to feature_range.

Defined in preprocessing/data.ts:488

Parameters:

ParamTypeDefaultDescription
Xnumber[]nullScaled input vector

Returns:

number[]

λ transform

Scaling features of X according to feature_range.

Defined in preprocessing/data.ts:468

Parameters:

ParamTypeDefaultDescription
Xnumber[] or number[][]nullOriginal input vector

Returns: