This object stores the predictions returned by a learner of class LearnerClassif. If probabilities are provided via construction and response is missing, the response is calculated from the probabilities: the class label with the highest probability is chosen. In case of ties, a random class label of the tied labels picked.

The task_type is set to "classif".

Format

R6::R6Class object inheriting from Prediction.

Construction

p = PredictionClassif$new(task = NULL, response = NULL, prob = NULL)
  • task :: TaskClassif
    Task for which the predictions are made. Used to extract the row ids and the true labels. Must be subsetted to test set.

  • response :: (factor() | character())
    Vector of predicted class labels. One element for each observation in the test set.

  • prob :: matrix()
    Numeric matrix of class probabilities with one column for each class and one row for each observation in the test set.

Note that it is allowed to initialize this object without any arguments in order to allow to manually construct Prediction objects in a piecemeal fashion. Required are "row_ids", "truth", and "predict_type". Depending on the value of "predict_types", also "response" and "prob" must be set.

Fields

  • row_ids :: (integer() | character())
    Vector of row ids for which predictions are stored.

  • truth :: any
    Vector of true labels.

  • response :: any
    Vector of predicted labels.

  • task_type :: character(1)
    Stores the type of the Task.

  • predict_types :: character()
    Vector of predict types this object stores.

See also

Other Prediction: PredictionRegr, Prediction

Examples

task = mlr_tasks$get("iris") learner = mlr_learners$get("classif.rpart") learner$predict_type = "prob" e = Experiment$new(task, learner)$train()$predict()
#> INFO [mlr3] Training learner 'rpart' on task 'iris' ... #> INFO [mlr3] Predicting with model of learner 'rpart' on task 'iris' ...
p = e$prediction p$predict_types
#> [1] "response" "prob"
#> row_id response truth prob.setosa prob.versicolor prob.virginica #> 1: 1 setosa setosa 1 0 0 #> 2: 2 setosa setosa 1 0 0 #> 3: 3 setosa setosa 1 0 0 #> 4: 4 setosa setosa 1 0 0 #> 5: 5 setosa setosa 1 0 0 #> 6: 6 setosa setosa 1 0 0