R/TaskRegr_mtcars.R

Defines functions load_task_mtcars

#' @title Motor Trend Regression Task
#'
#' @name mlr_tasks_mtcars
#' @format [R6::R6Class] inheriting from [TaskRegr].
#' @include mlr_tasks.R
#'
#' @description
#' A regression task for the [datasets::mtcars] data set.
#' Target variable is `mpg` (Miles/(US) gallon).
#' Rownames are stored as variable `"..rownames` with column role `"model"`.
#'
#' @section Construction:
#' ```
#' mlr_tasks$get("mtcars")
#' tsk("mtcars")
#' ```
#'
#' @section Meta Information:
#' `r rd_info(tsk("mtcars"))`
#'
#' @template seealso_task
NULL

load_task_mtcars = function(id = "mtcars") {
  b = as_data_backend(load_dataset("mtcars", "datasets", keep_rownames = TRUE), keep_rownames = "model")
  task = TaskRegr$new(id, b, target = "mpg", label = "Motor Trends")
  b$hash = task$man = "mlr3::mlr_tasks_mtcars"
  task$col_roles$name = "model"
  task$col_roles$feature = setdiff(task$col_roles$feature, "model")
  task
}

#' @include mlr_tasks.R
mlr_tasks$add("mtcars", load_task_mtcars)

Try the mlr3 package in your browser

Any scripts or data that you put into this service are public.

mlr3 documentation built on Nov. 17, 2023, 5:07 p.m.