
Ordinal encoding (Geron Ch 2, morie.fn hmord)
Source:R/geron_ml2_native.R
morie_geron_ordinal_encoding.RdInteger codes against a fixed level order; the codes are 0-based to match Python. Implies order AND equal spacing, which is why one-hot is the safer default for a linear model.
Examples
V <- c(1, 2, 3, 4, 5, 6, 7, 8)
morie_geron_ordinal_encoding(V)
#> $encoded
#> [,1]
#> [1,] 0
#> [2,] 1
#> [3,] 2
#> [4,] 3
#> [5,] 4
#> [6,] 5
#> [7,] 6
#> [8,] 7
#>
#> $categories
#> $categories[[1]]
#> [1] 1 2 3 4 5 6 7 8
#>
#>
#> $n_categories
#> [1] 8
#>
#> $estimate
#> [,1]
#> [1,] 0
#> [2,] 1
#> [3,] 2
#> [4,] 3
#> [5,] 4
#> [6,] 5
#> [7,] 6
#> [8,] 7
#>
#> $n
#> [1] 8
#>
#> $method
#> [1] "Ordinal (integer) encoding against a fixed level order"
#>