preprocessing.LabelEncoder

Encode labels with value between 0 and n_classes-1.

Usage

import { LabelEncoder } from 'machinelearn/preprocessing';

const labelEncoder = new LabelEncoder();
const labelX = ['amsterdam', 'paris', 'tokyo'];
labelEncoder.fit(labelX);
const transformX = ['tokyo', 'tokyo', 'paris'];
const result = labelEncoder.transform(transformX);
// [ 2, 2, 1 ]

Methods

Methods


λ fit

Fit label encoder

Defined in preprocessing/label.ts:25

Parameters:

ParamTypeDefaultDescription
Xstring[]nullInput data in array or matrix

Returns:

void

λ transform

Transform labels to normalized encoding.

Given classes of ['amsterdam', 'paris', 'tokyo']

It transforms ["tokyo", "tokyo", "paris"]

Into [2, 2, 1]

Defined in preprocessing/label.ts:40

Parameters:

ParamTypeDefaultDescription
Xstring[]nullInput data to transform according to the fitted state

Returns:

any[]