OneHotEncoder-class: class OneHotEncoder

OneHotEncoderR Documentation

class OneHotEncoder

Description

A class for encoding labels as a one-hot numeric array.

Super class

deepANN::Encoder -> OneHotEncoder

Public fields

categories

('NULL' | character vector)
Holds the labels for the input.

Methods

Public methods


Method new()

Creates a new instance of this R6 class.

Usage
OneHotEncoder$new(categories = NULL)
Arguments
categories

Desired categories of the input data. If NULL (default), the categories are automatically determined from the input data.


Method fit()

Extract labels from input.

Usage
OneHotEncoder$fit(x)
Arguments
x

The input, usually a factor.

Returns

The instance self itself.


Method transform()

Encode input to numeric values between 0 and n_labels-1.

Usage
OneHotEncoder$transform(x)
Arguments
x

The input that will be encoded.

Returns

The encoded x.


Method fit_transform()

Run fit() and transform().

Usage
OneHotEncoder$fit_transform(x)
Arguments
x

The input that will be encoded.

Returns

The encoded x.


Method inverse_transform()

Transform labels back to original encoding.

Usage
OneHotEncoder$inverse_transform(x)
Arguments
x

The data that will be transformed back.

Returns

The original encoded x.


Method clone()

The objects of this class are cloneable with this method.

Usage
OneHotEncoder$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples

x <- factor(c("small", "small", "medium", "large", "large", "medium", "small"), levels = c("small", "medium", "large"))
ohe <- OneHotEncoder$new()
xt <- ohe$fit_transform(x)
ohe$inverse_transform(xt)

stschn/deepANN documentation built on June 25, 2024, 7:27 a.m.