Computes average precision (AP) for binary probabilistic predictions.
Arguments
- x
either a numeric vector of predicted probabilities or scores when
refis supplied, or a fitted model object from which both response and predictions are extracted- ref
numeric vector of observed binary outcomes (0/1), the reference the predictions are scored against. Required when
xis a vector of predictions; ignored whenxis a model object.
Details
Average precision summarizes the precision-recall curve as
$$AP = \sum_n (R_n - R_{n-1}) P_n,$$
where \(P_n\) and \(R_n\) are precision and recall at the \(n\)-th distinct prediction threshold. Unlike metrics based on predicted class labels, average precision does not require a classification cutoff. Prediction values therefore need only be numeric scores; they are not restricted to the interval [0, 1].
