Merged
Conversation
OkonSamuel
reviewed
Mar 22, 2026
OkonSamuel
reviewed
Mar 22, 2026
OkonSamuel
reviewed
Mar 22, 2026
Make review suggestions. Co-authored-by: Okon Samuel <39421418+OkonSamuel@users.noreply.github.com>
Member
Author
|
@OkonSamuel Thanks for your review. All suggestions have been adopted. |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces #70. From that PR:
Docstring
AveragePrecision()Return a callable measure for computing the average precision. Aliases:
average_precision.AveragePrecision()(ŷ, y)Evaluate
AveragePrecision()on predictionsŷ, given ground truth observationsy. It is expected thatŷbe a vector of distributions over the binary set of unique elements ofy; specifically,ŷshould have eltype<:UnivariateFinitefrom the CategoricalDistributions.jl package.Average precision is the area under the empirical precision-recall curve, understood as a step function. This is to be contrasted with measures going under the name "area under the precision-recall curve", in which the step function is usually replaced by a piece-wise linear approximation. Generally, differences between the two are only obvious when the number of observations is small, but it is faster to compute average precision.
Reference: Wikipedia entry, Average precision
Definition
Adopting each distinct predicted probability$p_1, p_2, \ldots, p_k$ for the positive class as a soft probability threshold for predicting an actual class, and assuming these thresholds are arranged in decreasing order, we obtain corresponding recalls $R_1, R_2, \ldots, R_k$ (monotonically increasing) and precisions $P_1, P_2, \ldots, P_k$ . Adding an extra recall, $R_{k+1} = 1$ , the average precision implemented here is defined as
In some other implementations, such as scikit-learn,$P_j$ is replaced by $P_{j+1}$ . However, this requires the definition of a precision for unit recall, in the case the predicted positive class probabilities exclude
1.0, and this is avoided here.Core implementation:
Functions.average_precision.Generally, an observation
obsinMLUtils.eachobs(y)is expected to satisfyScientificTypes.scitype(obs)<:``ScientificTypesBase.OrderedFactor{2}.See also
precision_recall_curve.For a complete dictionary of available measures, keyed on constructor, run
measures().Traits