
One-hot encoding (Geron Ch 2, morie.fn hmohe)
Source:R/geron_ml2_native.R
morie_geron_one_hot_encoding.RdLevels default to the sorted unique values of each column. Column
names are x<j>=<level> with j 0-based, as in Python.
Examples
V <- c(1, 2, 3, 4, 5, 6, 7, 8)
morie_geron_one_hot_encoding(V)
#> $encoded
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
#> [1,] 1 0 0 0 0 0 0 0
#> [2,] 0 1 0 0 0 0 0 0
#> [3,] 0 0 1 0 0 0 0 0
#> [4,] 0 0 0 1 0 0 0 0
#> [5,] 0 0 0 0 1 0 0 0
#> [6,] 0 0 0 0 0 1 0 0
#> [7,] 0 0 0 0 0 0 1 0
#> [8,] 0 0 0 0 0 0 0 1
#>
#> $categories
#> $categories[[1]]
#> [1] 1 2 3 4 5 6 7 8
#>
#>
#> $names
#> [1] "x0=1" "x0=2" "x0=3" "x0=4" "x0=5" "x0=6" "x0=7" "x0=8"
#>
#> $n_columns
#> [1] 8
#>
#> $drop_first
#> [1] FALSE
#>
#> $estimate
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
#> [1,] 1 0 0 0 0 0 0 0
#> [2,] 0 1 0 0 0 0 0 0
#> [3,] 0 0 1 0 0 0 0 0
#> [4,] 0 0 0 1 0 0 0 0
#> [5,] 0 0 0 0 1 0 0 0
#> [6,] 0 0 0 0 0 1 0 0
#> [7,] 0 0 0 0 0 0 1 0
#> [8,] 0 0 0 0 0 0 0 1
#>
#> $n
#> [1] 8
#>
#> $method
#> [1] "One-hot indicator encoding"
#>