One-hot encoding

one_hot_encode(y)

Arguments

y

A vector of class labels

n_classes

The number of classes

Value

A matrix of one-hot encoded labels

Examples


y <- as.factor(c(1, 2, 1, 1, 2))
misc::one_hot_encode(y)
#>      [,1] [,2]
#> [1,]    1    0
#> [2,]    0    1
#> [3,]    1    0
#> [4,]    1    0
#> [5,]    0    1