Learn R Programming

superml (version 0.2.0)

LabelEncoder: Label Encoder

Description

Encodes and decodes categorical variables into integer values and vice versa. This is a commonly performed task in data preparation during model training, because all machine learning models require the data to be encoded into numerical format. It takes a vector of character or factor values and encodes them into numeric.

Usage

LabelEncoder

Format

R6Class object.

Usage

For usage details see Methods, Arguments and Examples sections.

lbl = LabelEncoder$new()
lbl$fit(x)
lbl$fit_transform(x)
lbl$transform(x)

Methods

$new()

Initialise the instance of the encoder

$fit()

creates a memory of encodings but doesn't return anything

$transform()

based on encodings learned in fit method is applies the transformation

$fit_transform()

encodes the data and keep a memory of encodings simultaneously

$inverse_transform()

encodes the data and keep a memory of encodings simultaneously

Arguments

data

a vector or list containing the character / factor values

Examples

Run this code
# NOT RUN {
data_ex <- data.frame(Score = c(10,20,30,4), Name=c('Ao','Bo','Bo','Co'))
lbl <- LabelEncoder$new()
data_ex$Name <- lbl$fit_transform(data_ex$Name)
decode_names <- lbl$inverse_transform(data_ex$Name)
# }

Run the code above in your browser using DataLab