Uses a cost matrix to create a classification measure. The cost matrix is stored as slot "costs". Costs are aggregated with the mean.

MeasureClassifCosts

Format

R6::R6Class() inheriting from MeasureClassif.

Construction

MeasureClassifCosts$new(costs = NULL, normalize = TRUE)
  • id :: character(1)
    Identifier for the measure.

  • costs :: matrix()
    Numeric matrix of costs (truth in columns, predicted response in rows).

  • normalize :: logical(1)
    If TRUE, calculate the mean costs instead of the total costs.

Examples

# get a cost sensitive task task = mlr_tasks$get("german_credit") # cost matrix as given on the UCI page of the german credit data set # https://archive.ics.uci.edu/ml/datasets/statlog+(german+credit+data) costs = matrix(c(0, 5, 1, 0), nrow = 2) dimnames(costs) = list(truth = task$class_names, predicted = task$class_names) print(costs)
#> predicted #> truth good bad #> good 0 1 #> bad 5 0
# mlr3 needs truth in columns, predictions in rows costs = t(costs) # create measure which calculates the absolute costs m = MeasureClassifCosts$new(id = "german_credit_costs", costs, normalize = FALSE) # fit models and calculate the costs resample(task, "classif.rpart", "cv3", measure = m)
#> INFO [mlr3] Running learner 'classif.rpart' on task 'german_credit' (iteration 1/3)' #> INFO [mlr3] Running learner 'classif.rpart' on task 'german_credit' (iteration 2/3)' #> INFO [mlr3] Running learner 'classif.rpart' on task 'german_credit' (iteration 3/3)'
#> <ResampleResult> of learner 'german_credit' on task 'classif.rpart' with 3 iterations #> Measure Min. 1st Qu. Median Mean 3rd Qu. Max. Sd #> german_credit_costs 270 288.5 307 320.7 346 385 58.71