mlr_measures_classif.costs {mlr3} | R Documentation |
Cost-sensitive Classification Measure
Description
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
.
For calculation of the score, the confusion matrix is multiplied element-wise with the cost matrix.
The costs are then summed up (and potentially divided by the number of observations if normalize
is set to TRUE
(default)).
Dictionary
This Measure can be instantiated via the dictionary mlr_measures or with the associated sugar function msr()
:
mlr_measures$get("classif.costs") msr("classif.costs")
Meta Information
Task type: “classif”
Range:
(-\infty, \infty)
Minimize: TRUE
Average: macro
Required Prediction: “response”
Required Packages: mlr3
Parameters
Id | Type | Default | Levels |
normalize | logical | - | TRUE, FALSE |
Super classes
mlr3::Measure
-> mlr3::MeasureClassif
-> MeasureClassifCosts
Active bindings
costs
(numeric
matrix()
)
Matrix of costs (truth in columns, predicted response in rows).
Methods
Public methods
Inherited methods
Method new()
Creates a new instance of this R6 class.
Usage
MeasureClassifCosts$new()
Method clone()
The objects of this class are cloneable with this method.
Usage
MeasureClassifCosts$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
See Also
Chapter in the mlr3book: https://mlr3book.mlr-org.com/chapters/chapter2/data_and_basic_modeling.html#sec-eval
Package mlr3measures for the scoring functions. Dictionary of Measures: mlr_measures
as.data.table(mlr_measures)
for a table of available Measures in the running session (depending on the loaded packages).Extension packages for additional task types:
-
mlr3proba for probabilistic supervised regression and survival analysis.
-
mlr3cluster for unsupervised clustering.
-
Other Measure:
Measure
,
MeasureClassif
,
MeasureRegr
,
MeasureSimilarity
,
mlr_measures
,
mlr_measures_aic
,
mlr_measures_bic
,
mlr_measures_debug_classif
,
mlr_measures_elapsed_time
,
mlr_measures_internal_valid_score
,
mlr_measures_oob_error
,
mlr_measures_selected_features
Other classification measures:
mlr_measures_classif.acc
,
mlr_measures_classif.auc
,
mlr_measures_classif.bacc
,
mlr_measures_classif.bbrier
,
mlr_measures_classif.ce
,
mlr_measures_classif.dor
,
mlr_measures_classif.fbeta
,
mlr_measures_classif.fdr
,
mlr_measures_classif.fn
,
mlr_measures_classif.fnr
,
mlr_measures_classif.fomr
,
mlr_measures_classif.fp
,
mlr_measures_classif.fpr
,
mlr_measures_classif.logloss
,
mlr_measures_classif.mauc_au1p
,
mlr_measures_classif.mauc_au1u
,
mlr_measures_classif.mauc_aunp
,
mlr_measures_classif.mauc_aunu
,
mlr_measures_classif.mbrier
,
mlr_measures_classif.mcc
,
mlr_measures_classif.npv
,
mlr_measures_classif.ppv
,
mlr_measures_classif.prauc
,
mlr_measures_classif.precision
,
mlr_measures_classif.recall
,
mlr_measures_classif.sensitivity
,
mlr_measures_classif.specificity
,
mlr_measures_classif.tn
,
mlr_measures_classif.tnr
,
mlr_measures_classif.tp
,
mlr_measures_classif.tpr
Other multiclass classification measures:
mlr_measures_classif.acc
,
mlr_measures_classif.bacc
,
mlr_measures_classif.ce
,
mlr_measures_classif.logloss
,
mlr_measures_classif.mauc_au1p
,
mlr_measures_classif.mauc_au1u
,
mlr_measures_classif.mauc_aunp
,
mlr_measures_classif.mauc_aunu
,
mlr_measures_classif.mbrier
,
mlr_measures_classif.mcc
Examples
# 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 a cost measure which calculates the absolute costs
m = msr("classif.costs", id = "german_credit_costs", costs = costs, normalize = FALSE)
# fit models and evaluate with the cost measure
learner = lrn("classif.rpart")
rr = resample(task, learner, rsmp("cv", folds = 3))
rr$aggregate(m)