mlr3: Machine Learning in R - Next Generation

Michel Lang, Bernd Bischl, Jakob Richter, Patrick Schratz, Martin Binder, Florian Pfisterer, Raphael Sonabend, Marc Becker, Sebastian FischerOpenalex Unknown 2019 · DOI · OpenAlex

Abstract

Efficient, object-oriented programming on the building blocks of machine learning. Provides 'R6' objects for tasks, learners, resamplings, and measures. The package is geared towards scalability and larger datasets by supporting parallelization and out-of-memory data-backends like databases. While 'mlr3' focuses on the core computational operations, add-on packages provide additional functionality.

Introduction

For years, the R ecosystem lacked a cohesive, high-performance framework capable of keeping pace with the increasing complexity of machine learning (ML) workflows and the expanding scale of modern datasets. While the original mlr package was a pioneer in the field, its architectural limitations eventually made it difficult to maintain and scale.

The mlr3 framework was developed from the ground up to address these challenges. By reimagining the core architecture, the authors focused on three primary objectives: scalability for datasets exceeding RAM capacity, modularity to allow for flexible component swapping, and robust parallelization to ensure that large-scale benchmarks remain stable even when individual model training steps fail.

Core Methodology

The foundation of mlr3 is built on R6 object-oriented programming. Unlike traditional S3 or S4 objects in R, R6 allows for mutable state and clearer encapsulation. This shift makes the framework more efficient and significantly easier for developers to extend.

Standardized Building Blocks

The framework defines four primary classes that serve as the modular components of any ML workflow:

  • Task: Contains the data and associated metadata (e.g., target variables).
  • Learner: Encapsulates the machine learning algorithms.
  • Resampling: Defines validation strategies like k-fold cross-validation.
  • Measure: Specifies the performance metrics for evaluation.

Scalability and Data Handling

mlr3 abstracts data access through specialized backends. While it defaults to the high-performance data.table package for in-memory operations, it can connect to out-of-memory databases (such as SQL or DuckDB) via the mlr3db extension. This allows the framework to process massive datasets without requiring them to be fully loaded into memory.

Robust Execution

To handle the instability often found in complex ML experiments, mlr3 utilizes packages like callr and mirai to run learners in isolated R sessions. This encapsulation ensures that if a specific model training step encounters a segmentation fault or a critical error, the broader benchmarking process continues uninterrupted. Furthermore, integration with the future ecosystem allows users to transition from local multi-core processing to distributed cluster computing with minimal code changes.

The "Lean Core" Ecosystem

A central philosophy of mlr3 is the "Lean Core." The base package is intentionally kept small to avoid dependency bloat and facilitate faster development cycles. Advanced functionality is provided through a suite of extension packages:

  • mlr3pipelines: For complex data preprocessing and workflow engineering.
  • mlr3tuning: For hyperparameter optimization.
  • mlr3viz: For standardized visualizations.
  • Specialized Domains: Extensions like mlr3proba (survival analysis), mlr3spatial (spatial data), and mlr3cluster (unsupervised learning) expand the framework's reach.

Key Insights and Performance

mlr3 achieves significant speedups in data manipulation by using data.table internally. It also introduces innovative features like hotstarting, which allows learners to resume training (e.g., adding trees to an existing Random Forest) without re-calculating previous iterations. The unified benchmark() function enables the simultaneous evaluation of multiple learners across multiple tasks, producing structured results that are easily filtered and aggregated.

Limitations and Future Directions

Despite its power, the transition to mlr3 involves a learning curve, as the R6 programming style is a departure from the functional programming patterns familiar to many R users. Additionally, "marshaling"—the process of serializing complex models containing external C++ pointers—remains a technical challenge for certain implementations.

Future development is focused on deepening integration with deep learning via mlr3torch and further optimizing prediction paths for high-throughput production environments. By providing a scalable, modular, and reliable foundation, mlr3 establishes a new standard for machine learning research and application within the R ecosystem.

Summary updated

Abstract

Efficient, object-oriented programming on the building blocks of machine learning. Provides 'R6' objects for tasks, learners, resamplings, and measures. The package is geared towards scalability and larger datasets by supporting parallelization and out-of-memory data-backends like databases. While 'mlr3' focuses on the core computational operations, add-on packages provide additional functionality.
BibTeX
@inproceedings{lang2019mlr,
  author = {Michel Lang and Bernd Bischl and Jakob Richter and Patrick Schratz and Martin Binder and Florian Pfisterer and Raphael Sonabend and Marc Becker and Sebastian Fischer},
  title = {{mlr3: Machine Learning in R - Next Generation}},
  booktitle = {Openalex Unknown},
  year = {2019},
  doi = {10.32614/cran.package.mlr3},
}
Figure