Skip to main content

Metrics for one label per image

Description

What to report beside the loss for task = “classification”. These are a different family from metrics rather than more of it: there is no overlap to measure, no background class to leave out, and no smooth - a label is right or it is not.

Usage

metric_accuracy()

metric_balanced_accuracy()

metric_f1()

metric_auc()

Details

They are also scored differently, and that is measured rather than stylistic. An overlap metric is a formula on counts, so averaging a batch’s scores is the score; three of these four are not means over images at all. On 4000 images at a prevalence of 3%, against a model whose own probabilities are the truth, pooling the whole pass against averaging batches of 8 moves balanced accuracy by 0.0035, macro F1 by 0.0734, and the AUC by up to 0.0371 in a direction that does not settle with a bigger batch - because at that prevalence 398 of 500 batches hold no positive at all, so a per-class recall is an average over whichever batches happened to contain the rare class. The engine therefore accumulates these over the pass and computes them once at the end.

metric_auc() is the engine’s default and the other three are offered rather than recommended. At a 3% prevalence a calibrated model never crosses the threshold, so everything read off the hard prediction sees the same all-negative answer: accuracy spans 0.0100 across models of genuinely different quality and is not even monotone - a model with no signal scores above two that have one - while the AUC spans 0.4631. Balanced accuracy and F1 do not rescue it; they move by 0.0000 and -0.0005 between a real signal and a collapse. Being threshold-free is the property that separates them.

So metric_accuracy() is here because it is the number people ask for, and its page says what it costs.

Value

A metric specification.

See Also

classifier(), metrics for masks, class_balance() for the prevalence these measurements are all about

Examples

library("rplatypus")

metric_auc()
$name
[1] "auc"
# The number people ask for, beside the one that can tell a signal from a collapse.
classifier("cnn", input_shape = c(128, 128),
           metrics = list(metric_auc(), metric_accuracy()))
$name
[1] "cnn"

$input_shape
[1] 128 128

$metrics
$metrics[[1]]
$metrics[[1]]$name
[1] "auc"


$metrics[[2]]
$metrics[[2]]$name
[1] "accuracy"



attr(,"task")
[1] "classification"