Skip to contents

Levels default to the sorted unique values of each column. Column names are x<j>=<level> with j 0-based, as in Python.

Usage

morie_geron_one_hot_encoding(X, drop_first = FALSE, categories = NULL)

Arguments

X

Vector or matrix of categories.

drop_first

Drop the reference level of each variable.

categories

Optional list of level vectors, one per column.

Value

List with encoded, categories, names, n_columns, drop_first, estimate, n.

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"
#>