R6 class to represent data to be used in estimating a model
R6 class to represent data to be used in estimating a model
This class provides consistent names and interfaces to data which will be used in a supervised regression / classification model.
label
The labels for the eventual model as a vector.
features
The matrix representation of the data to be used for model fitting.
Constructed using stats::model.matrix
.
model_frame
The data-frame representation of the data as constructed by
stats::model.frame
.
split_id
The split identifiers as a vector.
num_splits
The integer number of splits in the data.
cluster
A cluster ID as a vector, constructed using the unit identifiers.
weights
The case-weights as a vector.
new()
Creates an R6 object to represent data to be used in a prediction model.
Model_data$new(data, label_col, ..., .weight_col = NULL)
SL_cv_control()
A helper function to create the cross-validation options to be used by SuperLearner.
## ------------------------------------------------
## Method `Model_data$new`
## ------------------------------------------------
library("dplyr")
#>
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#>
#> filter, lag
#> The following objects are masked from ‘package:base’:
#>
#> intersect, setdiff, setequal, union
df <- dplyr::tibble(
uid = 1:100,
x1 = rnorm(100),
x2 = rnorm(100),
x3 = sample(4, 100, replace = TRUE)
) %>% dplyr::mutate(
y = x1 + x2 + x3 + rnorm(100),
x3 = factor(x3)
)
df <- make_splits(df, uid, .num_splits = 5)
data <- Model_data$new(df, y, x1, x2, x3)