mlr3: A modern object-oriented machine learning framework in R

Michel Lang, Martin Binder, Jakob Richter, Patrick Schratz, Florian Pfisterer, Stefan Coors, Quay Au, Giuseppe Casalicchio, Lars Kotthoff, Bernd BischlJ. Open Source Softw 2019 · DOI · DBLP

Introduction

The mlr3 package represents a ground-up reboot of the popular machine learning framework for the R programming language. Designed to be faster, more modular, and easier to maintain than its predecessor, mlr3 leverages modern R features to provide a scalable ecosystem suitable for everything from simple scripts to complex, multi-stage machine learning pipelines.

Addressing the Monolithic Bottleneck

In the R ecosystem, the original mlr package (released in 2013) was a pioneer in providing a unified interface for hundreds of different machine learning algorithms. However, over six years of development, it became a victim of its own success. As a monolithic package, it grew increasingly bloated; adding a single feature required testing dozens of dependencies, and a full build could take hours.

Architecturally, the legacy system struggled to support "cross-cutting" functionality, such as complex pipelines where data flows through multiple preprocessing and modeling steps, or high-performance computing on large datasets. The developers realized that to keep pace with the evolving ML landscape, a shift was necessary: moving away from a "one-size-fits-all" package toward a modular, extensible ecosystem.

Core Design Principles

The authors reimplemented the framework from scratch based on four core design principles:

  1. Modularity: The core mlr3 package is intentionally "light," containing only the essential building blocks: tasks, learners, and measures. Advanced features like hyperparameter tuning or feature selection are delegated to separate, specialized packages (e.g., mlr3tuning, mlr3filters). This prevents the core package from becoming a maintenance burden.
  2. Reference Semantics with R6: Unlike standard R objects that often use "copy-on-modify" behavior, mlr3 utilizes the R6 class system. This allows for true object-oriented design where objects can change their internal state without creating unnecessary memory copies—a crucial feature for memory-intensive machine learning tasks and complex state management in pipelines.
  3. High-Performance Backend: The framework leverages data.table, the gold standard for fast data manipulation in R, ensuring that the framework's overhead remains negligible compared to actual model training. This choice facilitates efficient handling of large-scale datasets.
  4. Defensive Programming: To mitigate the "garbage in, garbage out" problem, the authors integrated the checkmate package for rigorous input validation and type safety. This ensures that errors are caught early in the execution flow and that return types remain predictable across different learners and measures.

The Modular Ecosystem

By breaking the framework into a "constellation" of packages, the developers can update specific components without risking the stability of the entire system. This ecosystem approach has led to several key components:

  • mlr3learners: Provides a unified API for the most important machine learning algorithms in R, ensuring consistent interaction regardless of the underlying implementation.
  • mlr3tuning & mlr3filters: Decouples the logic of hyperparameter optimization and feature selection from the core modeling logic, allowing for more flexible experimental setups.
  • mlr3pipelines: Support for Directed Acyclic Graphs (DAGs), allowing researchers to build complex ensembles, stacking models, and alternative branch executions in a structured, reproducible way.
  • mlr3db: Provides interface for out-of-memory support, allowing users to work with datasets that exceed available RAM by connecting directly to database backends.

Key Insights and User Experience

A major improvement in user experience is that nearly all result objects in mlr3 are tabular. By combining data.table with list-columns of R6 objects, users can use standard "split-apply-combine" workflows to analyze their experiments. This approach allows for seamless integration with the broader data manipulation ecosystem in R. Furthermore, the framework's extensibility is designed to serve as a foundation for "meta-algorithms," such as Automated Machine Learning (AutoML) systems, which can be built on top of these modular components.

Conclusion and Future Work

While mlr3 provides a robust foundation, it remains an evolving project. The development team is actively expanding the ecosystem to include specialized domains such as Bayesian optimization, survival analysis, and spatial/temporal data handling. While the shift from functional R to an R6-heavy object-oriented system represents a learning curve for some traditional R users, the resulting framework offers the scalability and maintainability required for modern machine learning research and production environments.

Summary updated

BibTeX
@article{lang2019mlr,
  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 and Michel Lang and Martin Binder and Jakob Richter and Patrick Schratz and Florian Pfisterer and Stefan Coors and Quay Au},
  title = {{mlr3: A modern object-oriented machine learning framework in R}},
  journal = {J. Open Source Softw.},
  year = {2019},
  doi = {10.21105/joss.01903},
}
Figure