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.

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= 457 

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

 1) root 457 160 benign (0.35010941 0.64989059)  
   2) cell_shape=3,4,5,6,7,8,9,10 187  30 malignant (0.83957219 0.16042781)  
     4) bare_nuclei=2,3,4,5,6,7,8,9,10 160  10 malignant (0.93750000 0.06250000) *
     5) bare_nuclei=1 27   7 benign (0.25925926 0.74074074)  
      10) marg_adhesion=4,5,6,7,8,9,10 7   0 malignant (1.00000000 0.00000000) *
      11) marg_adhesion=1,2,3 20   0 benign (0.00000000 1.00000000) *
   3) cell_shape=1,2 270   3 benign (0.01111111 0.98888889) *
# 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 226 observations:
    row_ids     truth  response prob.malignant prob.benign
          3    benign    benign     0.01111111   0.9888889
         10    benign    benign     0.01111111   0.9888889
         17    benign    benign     0.01111111   0.9888889
---                                                       
        655 malignant malignant     0.93750000   0.0625000
        676 malignant malignant     0.93750000   0.0625000
        683 malignant malignant     0.93750000   0.0625000
predictions$score(msr("classif.auc"))
classif.auc 
  0.9021355 
autoplot(predictions, type = "roc")