Learners

To keep the dependencies on other packages reasonable, the base package mlr3 only ships with with regression and classification trees from the rpart package and some learners for debugging. A subjective selection of implementations for essential ML algorithms can be found in mlr3learners package. Survival learners are provided by mlr3proba, cluster learners via mlr3cluster. Additional learners, including some learners which are not yet to be considered stable or which are not available on CRAN, are connected via the mlr3extralearners package. For neural networks, see the mlr3torch extension.

Example Usage

Fit a classification tree on the Wisconsin Breast Cancer Data Set and predict on left-out observations.

library("mlr3verse")

# retrieve the task
task = tsk("breast_cancer")

# split into two partitions
split = partition(task)

# retrieve a learner
learner = lrn("classif.rpart", keep_model = TRUE, predict_type = "prob")

# fit decision tree
learner$train(task, split$train)

# access learned model
learner$model
n= 458 

node), split, n, loss, yval, (yprob)
      * denotes terminal node

1) root 458 155 benign (0.33842795 0.66157205)  
  2) cell_size=4,5,6,7,8,9,10 138   8 malignant (0.94202899 0.05797101) *
  3) cell_size=1,2,3 320  25 benign (0.07812500 0.92187500)  
    6) bare_nuclei=6,7,8,9,10 18   1 malignant (0.94444444 0.05555556) *
    7) bare_nuclei=1,2,3,4,5 302   8 benign (0.02649007 0.97350993) *
# predict on data frame with new data
predictions = learner$predict_newdata(task$data(split$test))

# predict on subset of the task
predictions = learner$predict(task, split$test)

# inspect predictions
predictions

── <PredictionClassif> for 225 observations: ───────────────────────────────────
 row_ids  truth response prob.malignant prob.benign
       3 benign   benign     0.02649007   0.9735099
      10 benign   benign     0.02649007   0.9735099
      14 benign   benign     0.02649007   0.9735099
     ---    ---      ---            ---         ---
     668 benign   benign     0.02649007   0.9735099
     670 benign   benign     0.02649007   0.9735099
     673 benign   benign     0.02649007   0.9735099
predictions$score(msr("classif.auc"))
classif.auc 
  0.9417427 
autoplot(predictions, type = "roc")