bacc: Balanced Accuracy

Description Usage Arguments Value Meta Information References See Also Examples

View source: R/classif_bacc.R

Description

Computes the weighted balanced accuracy, suitable for imbalanced data sets. It is defined analogously to the definition in sklearn.

First, the sample weights w are normalized per class:

w_hat[i] = w[i] / sum((t == t[i]) * w[i]).

The balanced accuracy is calculated as

1 / sum(w_hat) * sum((r == t) * w_hat).

Usage

1
bacc(truth, response, sample_weights = NULL, ...)

Arguments

truth

:: factor()
True (observed) labels. Must have the same levels and length as response.

response

:: factor()
Predicted response labels. Must have the same levels and length as truth.

sample_weights

:: numeric()
Non-negative sample weights. Must have the same levels and length as truth. Defaults to equal sample weights.

...

:: any
Additional arguments. Currently ignored.

Value

Performance value as numeric(1).

Meta Information

References

brodersen_2010

guyon_2015

See Also

Other Classification Measures: acc, ce, logloss

Examples

1
2
3
4
5
set.seed(1)
lvls = c("a", "b", "c")
truth = factor(sample(lvls, 10, replace = TRUE), levels = lvls)
response = factor(sample(lvls, 10, replace = TRUE), levels = lvls)
bacc(truth, response)

mlr3measures documentation built on Nov. 5, 2019, 9:06 a.m.