In this introduction, we fit a classification tree on the iris and determine the mean misclassification error.

Task and learner objects

First, we need to generate the following mlr3 objects from the task dictionary and the learner dictionary, respectively:

  1. The classification task

  2. A learner for the classification tree

Index vector for train/test splits

We opt to learn on \(\frac{4}{5}\) of all available observations and predict on the remaining \(\frac{1}{5}\) observations. For this purpose, we create two index vectors:

train.set = sample(task$nrow, 4/5 * task$nrow)
test.set = setdiff(seq_len(task$nrow), train.set)

Setting up an experiment

The process of fitting a machine learning model, predicting on test data and scoring the predictions by comparing predicted and true labels is called an experiment. For this reason, we start by initializing an Experiment object:

The printer shows a summary of the state of the experiment, which is currently [defined] and includes the task and the learner.


To train the learner on the task, we need to call the train function of the experiment:

The printer indicates that the Experiment object was modified (its state is now [trained]) and was also extended, since the object now includes a rpart model: