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 166 benign (0.362445415 0.637554585)  
  2) cell_size=3,4,5,6,7,8,9,10 177  19 malignant (0.892655367 0.107344633)  
    4) cell_shape=3,4,5,6,7,8,9,10 164  10 malignant (0.939024390 0.060975610) *
    5) cell_shape=1,2 13   4 benign (0.307692308 0.692307692) *
  3) cell_size=1,2 281   8 benign (0.028469751 0.971530249)  
    6) normal_nucleoli=3,4,5,6,7,8,9,10 9   3 malignant (0.666666667 0.333333333) *
    7) normal_nucleoli=1,2 272   2 benign (0.007352941 0.992647059) *
# 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
       1    benign    benign    0.007352941  0.99264706
       2    benign malignant    0.939024390  0.06097561
       7    benign    benign    0.007352941  0.99264706
     ---       ---       ---            ---         ---
     678    benign    benign    0.007352941  0.99264706
     679    benign    benign    0.007352941  0.99264706
     682 malignant malignant    0.939024390  0.06097561
predictions$score(msr("classif.auc"))
classif.auc 
  0.9492159 
autoplot(predictions, type = "roc")