preprocessing.Binarizer

Binarizer transform your data using a binary threshold. All values above the threshold are marked 1 and all equal to or below are marked as 0. It can also be used as a pre-processing step for estimators that consider boolean random variables (e.g. modelled using the Bernoulli distribution in a Bayesian setting).

Usage

import { Binarizer } from 'machinelearn/preprocessing';

const binX = [[1, -1, 2], [2, 0, 0], [0, 1, -1]];
const binarizer = new Binarizer({ threshold: 0 });
const result = binarizer.transform(binX);
// [ [ 1, 0, 1 ], [ 1, 0, 0 ], [ 0, 1, 0 ] ]

Constructors

Methods

Constructors


constructor

new Binarizer(__namedParameters: `object`)

Defined in preprocessing/data.ts:513

Parameters:

ParamTypeDefaultDescription
options.copybooleantrueFlag to clone the input value.
options.thresholdnumber0Feature values below or equal to this are replaced by 0, above it by 1.

Returns: Binarizer

Methods


λ fit

Currently fit does nothing

Defined in preprocessing/data.ts:543

Parameters:

ParamTypeDefaultDescription
Xnumber[][]nullDoes nothing

Returns:

void

λ transform

Transforms matrix into binarized form X = [[ 1., -1., 2.], [ 2., 0., 0.], [ 0., 1., -1.]] becomes array([[ 1., 0., 1.], [ 1., 0., 0.], [ 0., 1., 0.]])

Defined in preprocessing/data.ts:562

Parameters:

ParamTypeDefaultDescription
Xnumber[][]nullThe data to binarize.

Returns:

any[]