danfo.LabelEncoder

Encode target labels with value between 0 and n_classes-1.

class danfo.LabelEncoder

danfo.js provides the LabelEncoder class for encoding Series and Arrays to integer between 0 and n_classes -1. This is mostly used as a preprocessing step before most machine learning tasks.

The API is similar to sklearn's LabelEncoder, and provides a fit and transform method.

Examples

Label Encode values in a Series

const dfd = require('danfojs-node')

let data = ["dog","cat","man","dog","cat","man","man","cat"]
let series = new dfd.Series(data)

let encode = new dfd.LabelEncoder()

encode.fit(series)
console.log(encode);

let sf_enc = encode.transform(series.values)
console.log(sf_enc)

let new_sf = encode.transform(["dog","man"])
console.log(new_sf)

Labels not found in the original data used for fitting are represented with -1

See also OneHotEncoder and danfo.getDummies

Last updated

Was this helpful?