Portable bindings for long precision-recall records. Each split/class/fold
identifies one curve. The reserved fold label aggregate identifies pooled
predictions. Compiles to LineSeriesOption in
src/chart/line/LineSeries.ts, GridOption in
src/coord/cartesian/GridModel.ts, and LegendOption in
src/component/legend/LegendModel.ts.
Usage
PRConfig(
dat_path = NULL,
title = NULL,
origin = NULL,
writer = NULL,
legend_position = "top",
legend_placement = "outside",
legend_title = NULL,
recall = "recall",
precision = "precision",
ap = NULL,
prevalence = NULL,
class_label = NULL,
split = NULL,
fold = NULL,
omitted = NULL,
variant = "aggregate",
digits = 3L,
baseline = TRUE,
palette = NULL,
legend = TRUE,
square = TRUE,
line_width = 2,
fold_opacity = 0.45,
xlab = "Recall",
ylab = "Precision"
)Arguments
- dat_path
Optional Character: Path to the data, read at draw time. The serializable alternative to passing
datatodraw().- title
Optional Character: Chart title.
- origin
Optional Named character {"user", "default", "derived"}: Where each value came from, one entry per settable property. Absent on an authored config; written by the interface that resolved it.
- writer
Optional Named character: Which interface wrote the config, as
nameandversion. Absent on an authored config.- legend_position
Character {"top", "bottom", "left", "right", "top-left", "top-right", "bottom-left", "bottom-right"}: Legend anchor. Top/bottom anchors use horizontal rows; left/right anchors use a vertical column. Corner anchors align within the top or bottom row.
- legend_placement
Character {"outside", "inside"}: Relation to the plotting area. Outside placement reserves space for the complete legend; inside placement overlays the data. Neither setting adds a missing legend.
- legend_title
Optional Character: Title drawn with the legend or colorbar: above left/right legends and vertical colorbars, before the first row of top/bottom legends and horizontal colorbars.
NULLdraws no title. A title does not add a missing legend.- recall
Character: Column containing recall values.
- precision
Character: Column containing precision values.
- ap
Optional Character: Optional supplied average precision column; unset computes it from the supplied vertices.
- prevalence
Optional Character: Optional positive-class prevalence column, constant within each curve.
- class_label
Optional Character: Optional positive-class label column.
- split
Optional Character: Optional sample or model label column.
- fold
Optional Character: Optional resample column; aggregate identifies pooled curves.
- omitted
Optional Character: Optional omitted-observation count column, constant within each curve.
- variant
Character: Draw pooled curves or separate resample curves.
- digits
Integer: Decimal places for average precision labels and tooltip values.
- baseline
Logical: Show the prevalence baseline of each curve group.
- palette
Optional Character: Group colors; unset uses the chart theme.
- legend
Logical: Show group labels and average precision summaries.
- square
Logical: Keep the plotting grid square.
- line_width
Numeric: Curve stroke width in pixels.
- fold_opacity
Numeric: Opacity of individual resample curves.
- xlab
Character: Horizontal axis label.
- ylab
Character: Vertical axis label.
Statistical semantics
Vertices are ordered by recall, then by decreasing precision, which is threshold order. Curves must include recall 0 and recall 1. Consecutive vertices are joined by steps: precision holds its value at each vertex back to the previous recall, so the area under the drawn curve is the average precision, \(\sum_k (R_k - R_{k-1}) P_k\). Precision is not linear in recall between two points of the curve, so a straight segment misstates the attainable values (Davis and Goadrich, 2006).
Supplied average precision is authoritative and may describe a
higher-resolution curve. Without an ap binding, the supplied vertices
define it. An undefined curve is represented by missing recall, precision,
and average precision and is reported in the console when omitted.
Per-resample legends report the unweighted mean and sample SD of average
precision over defined folds. SD is NA for one defined fold. Pooled average
precision is never inferred from per-fold values.
The chance level of a curve is the prevalence of its positive class, the expected precision of a classifier that scores independently of the label (Saito and Rehmsmeier, 2015). Prevalence differs by class and sample, so each curve group draws its own dotted baseline, in the group color, at the mean prevalence of its defined folds. The baseline toggles with its curves in the legend.
The legend uses the shared position and placement controls. Hover describes
the selected curve, including its resample identifier. Numeric tooltip labels
use digits; coordinates and summaries retain their full precision in the
compiled data.
References
Davis J, Goadrich M (2006). The relationship between precision-recall and ROC curves. Proceedings of the 23rd International Conference on Machine Learning, 233-240. doi:10.1145/1143844.1143874
Saito T, Rehmsmeier M (2015). The precision-recall plot is more informative than the ROC plot when evaluating binary classifiers on imbalanced datasets. PLoS ONE, 10(3), e0118432. doi:10.1371/journal.pone.0118432
Examples
draw(
setup_PRConfig(),
data = data.frame(recall = c(0, 0.5, 1), precision = c(1, 1, 0.5))
)