one_hot: One hot encoding

Description Usage Arguments Value Note Examples

Description

A faster implementation of mltools::one_hot with less options.

Usage

1

Arguments

data

a data frame

Value

a data.table with one-hot encoded factors.

Note

One-hot-encoding converts an unordered categorical vector (i.e. a factor) to multiple binarized vectors where each binary vector of 1s and 0s indicates the presence of a class (i.e. level) of the of the original vector.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
n <- 10

data <- data.frame(
  V1 = seq(n),
  V2 = factor(sample(letters[1:3], n, replace = TRUE)),
  V3 = seq(n) / 10,
  V4 = factor(sample(letters[5:6], n, replace = TRUE))
)

data$V1[1] <- NA
data$V3[c(6,7)] <- NA
data$V2[1:2] <- NA
data$V4[2] <- NA

one_hot(data)

bcjaeger/ipa documentation built on May 7, 2020, 9:45 a.m.