Description Usage Format Usage Methods Arguments Examples
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.
1 |
R6Class
object.
For usage details see Methods, Arguments and Examples sections.
1 2 3 4 | lbl = LabelEncoder$new()
lbl$fit(x)
lbl$fit_transform(x)
lbl$transform(x)
|
$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
a vector or list containing the character / factor values
1 2 3 4 | 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.