Uses a cost matrix to create a classification measure.
True labels must be arranged in columns, predicted labels must be arranged in rows.
The cost matrix is stored as slot
Costs are aggregated with the mean.
R6::R6Class() inheriting from MeasureClassif.
1 2 3
Numeric matrix of costs (truth in columns, predicted response in rows).
TRUE, calculate the mean costs instead of the total costs.
Dictionary of Measures: mlr_measures
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
# get a cost sensitive task task = tsk("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) # mlr3 needs truth in columns, predictions in rows costs = t(costs) # create measure which calculates the absolute costs m = msr("classif.costs", id = "german_credit_costs", costs = costs, normalize = FALSE) # fit models and calculate costs learner = lrn("classif.rpart") rr = resample(task, learner, rsmp("cv", folds = 3)) rr$aggregate(m)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.