True Negative Rate
MLMetrics.true_negative_rate — Function.true_negative_rate(targets, outputs, [encoding], [avgmode = :none]) -> Union{Float64, Dict}Return the fraction of negative predicted outcomes that are true negatives according to the corresponding targets. This is also known as specificity. 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_negatives, condition_negative, true_positive_rate (aka "recall" or "sensitivity")
Examples
julia> true_negative_rate([0,1,1,0,1], [1,1,1,0,1])
0.5
julia> true_negative_rate([-1,1,1,-1,1], [1,1,1,-1,1])
0.5
julia> true_negative_rate([:a,:b,:a,:c,:c], [:a,:c,:b,:c,:c], LabelEnc.OneVsRest(:b))
0.75
julia> true_negative_rate([:a,:b,:a,:c,:c], [:a,:c,:b,:c,:c]) # avgmode=:none
Dict{Symbol,Float64} with 3 entries:
:a => 1.0
:b => 0.75
:c => 0.666667
julia> true_negative_rate([:a,:b,:a,:c,:c], [:a,:c,:b,:c,:c], avgmode=:micro)
0.8
julia> true_negative_rate([:a,:b,:a,:c,:c], [:a,:c,:b,:c,:c], avgmode=:macro)
0.8055555555555555