For an x/y interface, matrix_to_dataset() converts the data to proper
encodings then formats the results for consumption by torch.
Arguments
- x
A numeric matrix of predictors.
- y
A vector. If regression than
yis numeric. For classification, it is a factor.- device
A single character string for the device to use (e.g.,
"cpu"or"cuda"). The default ofNULLuses the CPU. See training_efficiency.
Examples
if (torch::torch_is_installed()) {
matrix_to_dataset(as.matrix(mtcars[, -1]), mtcars$mpg)
}
#> <tensor_dataset>
#> Inherits from: <dataset>
#> Public:
#> .getbatch: function (index)
#> .getitem: function (index, ..., drop = TRUE)
#> .length: function ()
#> clone: function (deep = FALSE)
#> initialize: function (...)
#> load_state_dict: function (x, ..., .refer_to_state_dict = FALSE)
#> state_dict: function ()
#> tensors: list
