make_dummies | R Documentation |
Initiate the making of dummy variables
make_dummies(traindata, testdata)
traindata |
data.table or data.frame. |
testdata |
data.table or data.frame. New data that has the same
feature names, types, and levels as |
A list that contains the following entries:
List. Output from check_features
A data.frame containing all of the factors in traindata
as
one-hot encoded variables.
A data.frame containing all of the factors in testdata
as
one-hot encoded variables.
Original traindata with correct column ordering and factor levels. To be passed to
shapr.
Original testdata with correct column ordering and factor levels. To be passed to
explain.
Annabelle Redelmeier, Martin Jullum
if (requireNamespace("MASS", quietly = TRUE)) {
data("Boston", package = "MASS")
x_var <- c("lstat", "rm", "dis", "indus")
y_var <- "medv"
x_train <- as.data.frame(Boston[401:411, x_var])
y_train <- Boston[401:408, y_var]
x_test <- as.data.frame(Boston[1:4, x_var])
# convert to factors for illustational purpose
x_train$rm <- factor(round(x_train$rm))
x_test$rm <- factor(round(x_test$rm), levels = levels(x_train$rm))
dummylist <- make_dummies(traindata = x_train, testdata = x_test)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.