Positive Predictive Value
MLMetrics.positive_predictive_value — Function.positive_predictive_value(targets, outputs, [encoding], [avgmode = :none]) -> Union{Float64, Dict}Return the fraction of positive predicted outcomes in outputs that are true positives according to the correspondig targets. This is also known as "precision" (alias precision_score). Which value(s) denote "positive" or "negative" depends on the given (or inferred) encoding.
If encoding is omitted, the appropriate MLLabelUtils.LabelEncoding will be inferred from the types and/or values of targets and outputs. Note that omitting the encoding can cause performance penalties, which may include a lack of return-type inference.
The return value of the function depends on the number of labels in the given encoding and on the specified avgmode. In case an avgmode other than :none is specified, or the encoding is binary (i.e. it has exactly 2 labels), a single number is returned. Otherwise, the function will compute a separate result for each individual label, where that label is treated as "positive" and the other labels are treated as "negative". These results are then returned as a single dictionary with an entry for each label.
Arguments
targets::AbstractArray: The array of ground truths $\mathbf{y}$.outputs::AbstractArray: The array of predicted outputs $\mathbf{\hat{y}}$.encoding: Optional. Specifies the possible values intargetsandoutputsand their interpretation (e.g. what constitutes as a positive or negative label, how many labels exist, etc). It can either be an object from the namespaceLabelEnc, or a vector of labels.avgmode: Optional keyword argument. Specifies if and how class-specific results should be aggregated. This is mainly useful if there are more than two classes. Typical values are:none(default),:microfor micro averaging, or:macrofor macro averaging. It is also possible to specifyavgmodeas a type-stable positional argument using an object from theAvgModenamespace.
See also
true_positives, predicted_positive, true_positive_rate (aka "recall" or "sensitivity"), f_score
Examples
julia> precision_score([0,1,1,0,1], [1,1,1,0,1])
0.75
julia> precision_score([-1,1,1,-1,1], [1,1,1,-1,1])
0.75
julia> precision_score([:a,:b,:a,:c,:c], [:a,:c,:b,:c,:c], LabelEnc.OneVsRest(:c))
0.6666666666666666
julia> precision_score([:a,:b,:a,:c,:c], [:a,:c,:b,:c,:c]) # avgmode=:none
Dict{Symbol,Float64} with 3 entries:
:a => 1.0
:b => 0.0
:c => 0.666667
julia> precision_score([:a,:b,:a,:c,:c], [:a,:c,:b,:c,:c], avgmode=:micro)
0.6
julia> precision_score([:a,:b,:a,:c,:c], [:a,:c,:b,:c,:c], avgmode=:macro)
0.5555555555555555