Skip to contents

Native implementation of multi-class precision matching the four yardstick estimators ("binary", "macro", "macro_weighted", "micro"). Per-class precision is TP / (TP + FP); macro and micro aggregation follow Sokolova & Lapalme (2009), Table 3 (the arithmetic mean and the pooled-counts forms respectively). Macro-weighted is the truth-prevalence-weighted mean of per-class precisions. Returns NaN when the denominator is zero (no instances predicted for that class), matching yardstick's default.

Usage

metric_precision(
  truth,
  estimate,
  estimator = c("binary", "macro", "macro_weighted", "micro"),
  event_level = c("first", "second")
)

Arguments

truth

Factor (or coercible) of true class labels.

estimate

Factor (or coercible) of predicted class labels. Must take values from the same level set as truth.

estimator

One of "binary" (exactly two classes; uses event_level), "macro" (unweighted mean of per-class precisions), "macro_weighted" (mean weighted by truth-class prevalence), or "micro" (pooled TP and FP across all classes; for single-label multi-class data this equals accuracy).

event_level

For estimator = "binary": which level is the positive event, "first" (default) or "second".

Value

A single numeric value.

References

Sokolova, M., & Lapalme, G. (2009). A systematic analysis of performance measures for classification tasks. Information Processing & Management, 45(4), 427-437. doi:10.1016/j.ipm.2009.03.002

Manning, C. D., Raghavan, P., & Schutze, H. (2008). Introduction to Information Retrieval, Chapter 13. Cambridge University Press. (Free online: https://nlp.stanford.edu/IR-book/)