mlr3: Machine Learning in R - next generation
lgr::get_logger("mlr3")$set_threshold("warn")
set.seed(1)
options(datatable.print.class = FALSE, datatable.print.keys = FALSE)
Package website: release | dev
Efficient, object-oriented programming on the building blocks of machine learning.
Successor of mlr.
mlr3
is used in the demos and exercises.Install the last release from CRAN:
install.packages("mlr3")
Install the development version from GitHub:
remotes::install_github("mlr-org/mlr3")
If you want to get started with mlr3
, we recommend installing the mlr3verse meta-package which installs mlr3
and some of the most important extension packages:
install.packages("mlr3verse")
library(mlr3)
# create learning task
task_penguins = as_task_classif(species ~ ., data = palmerpenguins::penguins)
task_penguins
# load learner and set hyperparameter
learner = lrn("classif.rpart", cp = .01)
# train/test split
split = partition(task_penguins, ratio = 0.67)
# train the model
learner$train(task_penguins, split$train_set)
# predict data
prediction = learner$predict(task_penguins, split$test_set)
# calculate performance
prediction$confusion
measure = msr("classif.acc")
prediction$score(measure)
# 3-fold cross validation
resampling = rsmp("cv", folds = 3L)
# run experiments
rr = resample(task_penguins, learner, resampling)
# access results
rr$score(measure)[, .(task_id, learner_id, iteration, classif.acc)]
rr$aggregate(measure)
Consult the wiki for short descriptions and links to the respective repositories.
For beginners, we strongly recommend to install and load the mlr3verse package for a better user experience.
mlr was first released to CRAN in 2013.
Its core design and architecture date back even further.
The addition of many features has led to a feature creep which makes mlr hard to maintain and hard to extend.
We also think that while mlr was nicely extensible in some parts (learners, measures, etc.), other parts were less easy to extend from the outside.
Also, many helpful R libraries did not exist at the time mlr was created, and their inclusion would result in non-trivial API changes.
mlr
nicely.data.table
for fast and convenient data frame computations.data.table
and R6
, for this we will make heavy use of list columns in data.tables.checkmate
.sapply()
or drop
argument in [.data.frame
) are avoided.mlr3
requires the following packages at runtime:
parallelly
:future.apply
:future
abstraction interfacing many parallel backends.backports
:mlr
team.checkmate
:mlr
team.mlr3misc
:mlr
team.paradox
:mlr
team.R6
:data.table
:data.frame
.digest
(via mlr3misc
):uuid
:lgr
:mlr3measures
:mlbench
:palmerpenguins
:This R package is licensed under the LGPL-3.
If you encounter problems using this software (lack of documentation, misleading or wrong documentation, unexpected behavior, bugs, …) or just want to suggest features, please open an issue in the issue tracker.
Pull requests are welcome and will be included at the discretion of the maintainers.
Please consult the wiki for a style guide, a roxygen guide and a pull request guide.
If you use mlr3, please cite our JOSS article:
toBibtex(citation("mlr3"))