preprocessing.normalize

normalize(X: `object`, __namedParameters: `object`)

Data normalization is a process of scaling dataset based on Vector Space Model, and by default, it uses L2 normalization. At a higher level, the chief difference between the L1 and the L2 terms is that the L2 term is proportional to the square of the β values, while the L1 norm is proportional the absolute value of the values in β .

Usage

import { normalize } from 'machinelearn/preprocessing';

const result = normalize([
  [1, -1, 2],
  [2, 0, 0],
  [0, 1, -1],
], { norm: 'l2' });
console.log(result);
// [ [ 0.4082482904638631, -0.4082482904638631, 0.8164965809277261 ],
// [ 1, 0, 0 ],
// [ 0, 0.7071067811865475, -0.7071067811865475 ] ]

Defined in preprocessing/data.ts:700

Parameters:

ParamTypeDefaultDescription
Xnumber[][]nullThe data to normalize
options.normstring"l2"The norm to use to normalize each non zero sample; can be either 'l1' or 'l2'

Returns:

number[][]