This task specializes mlr3::Task, mlr3::TaskSupervised and mlr3::TaskRegr for forecasting problems.
The target column is assumed to be numeric.
The task_type
is set to "fcst"
.
It is recommended to use as_task_fcst()
for construction.
Predefined tasks are stored in the dictionary mlr3::mlr_tasks.
See also
Chapter in the mlr3book: https://mlr3book.mlr-org.com/chapters/chapter2/data_and_basic_modeling.html
Package mlr3data for more toy tasks.
Package mlr3oml for downloading tasks from https://www.openml.org.
Package mlr3viz for some generic visualizations.
as.data.table(mlr_tasks)
for a table of available Tasks in the running session (depending on the loaded packages).mlr3fselect and mlr3filters for feature selection and feature filtering.
Extension packages for additional task types:
Unsupervised clustering: mlr3cluster
Probabilistic supervised regression and survival analysis: https://mlr3proba.mlr-org.com/.
Other Task:
mlr_tasks_airpassengers
,
mlr_tasks_electricity
,
mlr_tasks_livestock
,
mlr_tasks_lynx
,
mlr_tasks_usaccdeaths
Super classes
mlr3::Task
-> mlr3::TaskSupervised
-> mlr3::TaskRegr
-> TaskFcst
Active bindings
properties
(
character()
)
Set of task properties. Possible properties are are stored in mlr_reflections$task_properties. The following properties are currently standardized and understood by tasks in mlr3:"strata"
: The task is resampled using one or more stratification variables (role"stratum"
)."groups"
: The task comes with grouping/blocking information (role"group"
)."weights"
: The task comes with observation weights (role"weight"
)."ordered"
: The task has columns which define the row order (role"order"
)."keys"
: The task has columns which define the time series"key"
).
Note that above listed properties are calculated from the
$col_roles
and may not be set explicitly.order
(
data.table::data.table()
)
If the task has a column with designated role"order"
, a table with two or more columns:Returns
NULL
if there are is no order column.key
(
data.table::data.table()
)
If the task has a column with designated role"key"
, a table with two or more columns:If there is only one key column, it will be named as
key
. ReturnsNULL
if there are are no key columns.
Methods
Inherited methods
mlr3::Task$add_strata()
mlr3::Task$cbind()
mlr3::Task$divide()
mlr3::Task$droplevels()
mlr3::Task$filter()
mlr3::Task$format()
mlr3::Task$formula()
mlr3::Task$head()
mlr3::Task$help()
mlr3::Task$levels()
mlr3::Task$missings()
mlr3::Task$rbind()
mlr3::Task$rename()
mlr3::Task$select()
mlr3::Task$set_col_roles()
mlr3::Task$set_levels()
mlr3::Task$set_row_roles()
mlr3::TaskRegr$truth()
Method new()
Creates a new instance of this R6 class.
The function as_task_fcst()
provides an alternative way to construct forecast tasks.
Arguments
id
(
character(1)
)
Identifier for the new instance.backend
(mlr3::DataBackend)
Either a mlr3::DataBackend, or any object which is convertible to a mlr3::DataBackend withas_data_backend()
. E.g., adata.frame()
will be converted to a mlr3::DataBackendDataTable.target
(
character(1)
)
Name of the target column.order
(
character(1)
)
Name of the order column.key
(
character(1)
)
Name of the key column.freq
(
character(1)
|integer(1)
)
Frequency of the time series. Either a positive number or one of the following:"secondly"
"minutely"
"hourly"
"daily"
"weekly"
"monthly"
"quarterly"
"yearly"
label
(
character(1)
)
Label for the new instance.extra_args
(named
list()
)
Named list of constructor arguments, required for converting task types viamlr3::convert_task()
.
Method data()
Returns a slice of the data from the mlr3::DataBackend as a data.table
.
Rows default to observations with role "use"
, and
columns default to features with roles "target"
, "order"
or "feature"
.
If rows
or cols
are specified which do not exist in the mlr3::DataBackend,
an exception is raised.
Rows and columns are returned in the order specified via the arguments rows
and cols
.
If rows
is NULL
, rows are returned in the order of task$row_ids
.
If cols
is NULL
, the column order defaults to
c(task$target_names, task$feature_names)
.
Note that it is recommended to not rely on the order of columns, and instead always
address columns with their respective column name.
Arguments
rows
(positive
integer()
)
Vector or row indices.cols
(
character()
)
Vector of column names.ordered
(
logical(1)
)
IfTRUE
, data is ordered according to the columns with column role"order"
.
Returns
Depending on the mlr3::DataBackend, but usually a data.table::data.table()
.
Examples
library(data.table)
airpassengers = tsbox::ts_dt(AirPassengers)
setnames(airpassengers, c("month", "passengers"))
task = as_task_fcst(airpassengers, target = "passengers", order = "month", freq = "monthly")
task$task_type
#> [1] "fcst"
task$formula()
#> passengers ~ .
#> NULL
task$truth()
#> [1] 112 118 132 129 121 135 148 148 136 119 104 118 115 126 141 135 125 149
#> [19] 170 170 158 133 114 140 145 150 178 163 172 178 199 199 184 162 146 166
#> [37] 171 180 193 181 183 218 230 242 209 191 172 194 196 196 236 235 229 243
#> [55] 264 272 237 211 180 201 204 188 235 227 234 264 302 293 259 229 203 229
#> [73] 242 233 267 269 270 315 364 347 312 274 237 278 284 277 317 313 318 374
#> [91] 413 405 355 306 271 306 315 301 356 348 355 422 465 467 404 347 305 336
#> [109] 340 318 362 348 363 435 491 505 404 359 310 337 360 342 406 396 420 472
#> [127] 548 559 463 407 362 405 417 391 419 461 472 535 622 606 508 461 390 432