Machine Learning in R

Website of the mlr3 ecosystem

An open-source machine learning framework providing a unified interface for machine learning in the R language.

A well designed and easy to learn interface.
More than 100 connected machine learning algorithms.
Light on dependencies.
Quick parallelization with the future package.
State-of-the-art optimization algorithms.
Dataflow programming with pipelines.

GitHub Mattermost Twitter StackOverflow

Quick Start

The mlr3verse meta-package installs mlr3 and some of the most important extension packages:

install.packages("mlr3verse")

Basic Example

Simple resampling:

  1. Load task and learner. Optionally, set hyperparameter values.
  2. Choose resampling strategy.
  3. Run automatic resampling
  4. Score with classification accuracy
library(mlr3verse)

task = tsk("penguins")
learner = lrn("classif.rpart", cp = .01)

resampling = rsmp("cv", folds = 3L)

rr = resample(task, learner, resampling)

rr$score(msr("classif.acc"))

Tuning Example

Quick tuning of a simple classification tree on the on penguins data set:

  1. Choose task.
  2. Load learner and set search space in one go.
  3. Run hyperparameter tuning with random search.
  4. Get best performing hyperparameter configuration.
library(mlr3tuningspaces)

task = tsk("penguins")

learner = lts(lrn("classif.rpart"))

instance = tune(
  method = "random_search",
  task = task,
  learner = learner,
  resampling = rsmp("cv", folds = 3),
  measure = msr("classif.acc"),
  term_evals = 10,
  batch_size = 5
)

instance$result

Pipelines Example

Create a stacked learner:

  1. Load task.
  2. Choose list of base learners and super learner.
  3. Convert to graph learner.
  4. Train on german credit task.
library(mlr3verse)
library(mlr3pipelines)

task = tsk("german_credit")

base_learners = list(
  lrn("classif.rpart", predict_type = "prob"),
  lrn("classif.kknn", predict_type = "prob")
)
super_learner = lrn("classif.log_reg")

graph_stack = pipeline_stacking(base_learners, super_learner)
graph_learner = as_learner(graph_stack)

graph_learner$train(task)

Citing mlr3

If you use mlr3, please cite our JOSS article:

@Article{mlr3,
  title = {{mlr3}: A modern object-oriented machine learning framework in {R}},
  author = {Michel Lang and Martin Binder and Jakob Richter and Patrick Schratz and Florian Pfisterer and Stefan Coors and Quay Au and Giuseppe Casalicchio and Lars Kotthoff and Bernd Bischl},
  journal = {Journal of Open Source Software},
  year = {2019},
  month = {dec},
  doi = {10.21105/joss.01903},
  url = {https://joss.theoj.org/papers/10.21105/joss.01903},
}