Description Usage Arguments Value Examples
xgboost
(and many other) modeling functions
expect matrix input with factor levels one-hot encoded.
cat_spread
will one-hot encode any factor or character variable
in data
and return a one-hot encoded tibble
. Alternatively,
cat_gather
will apply the inverse operation and convert one-hot
encoded columns back into factors.
1 2 3 | cat_spread(data, ...)
cat_gather(data, factor_levels)
|
data |
data with categorical variables (i.e., factors) that need to be spread or gathered. |
... |
Arguments passed on to
|
factor_levels |
This parameter is only relevant for
|
a tibble with categorical variables herded as you like.
1 2 3 4 | df <- data.frame(x = rep(letters[1:2], 50), y = 1:100)
one_hot_df <- cat_spread(df)
cat_gather(one_hot_df, factor_levels = list(x=c('a','b')))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.