Negative Likelihood Ratio
MLMetrics.negative_likelihood_ratio — Function.negative_likelihood_ratio(targets, outputs, [encoding], [avgmode = :none]) -> Union{Float64, Dict}Compute the negative likelihood ratio for the given outputs and targets. It is a useful meassure for assessing the quality of a diagnostic test and is defined as (1 - sensitivity) / specificity. This can also be written as false_negative_rate / true_negative_rate. 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
false_negative_rate, true_negative_rate (aka "specificity"), positive_likelihood_ratio, diagnostic_odds_ratio
Examples
julia> negative_likelihood_ratio([0,1,1,0,1], [1,0,1,0,1])
0.6666666666666666
julia> negative_likelihood_ratio([-1,1,1,-1,1], [1,-1,1,-1,1])
0.6666666666666666
julia> negative_likelihood_ratio([:b,:b,:a,:c,:c], [:a,:c,:b,:c,:c], LabelEnc.OneVsRest(:a))
1.3333333333333333
julia> negative_likelihood_ratio([:b,:b,:a,:c,:c], [:a,:c,:b,:c,:c]) # avgmode=:none
Dict{Symbol,Float64} with 3 entries:
:a => 1.33333
:b => 1.5
:c => 0.0
julia> negative_likelihood_ratio([:b,:b,:a,:c,:c], [:a,:c,:b,:c,:c], avgmode=:micro)
0.8571428571428572
julia> negative_likelihood_ratio([:b,:b,:a,:c,:c], [:a,:c,:b,:c,:c], avgmode=:macro)
0.9600000000000002