Compute binary classification positive and negative likelihood ratios.
The positive likelihood ratio is LR+=sensitivity/
where the sensitivity or recall is the ratio and the
specificity is . The negative likelihood ratio is . Here is the number of true positives,
the number of false positives, is the number of true negatives and
the number of false negatives. Both class likelihood ratios can be used
to obtain post-test probabilities given a pre-test probability.
(1
-
specificity)
tp/(tp+fn)
tn/(tn+fp)
LR-=(1-sensitivity)/specificity
tp
fp
tn
fn
LR+ ranges from 1.0 to infinity. A LR+ of 1.0 indicates that the probability
of predicting the positive class is the same for samples belonging to either
class; therefore, the test is useless. The greater LR+ is, the more a
positive prediction is likely to be a true positive when compared with the
pre-test probability. A value of LR+ lower than 1.0 is invalid as it would
indicate that the odds of a sample being a true positive decrease with
respect to the pre-test odds.
LR- ranges from 0.0 to 1.0. The closer it is to 0.0, the lower the probability
of a given sample to be a false negative. A LR- of 1.0 means the test is
useless because the odds of having the condition did not change after the
test. A value of LR- greater than 1.0 invalidates the classifier as it
indicates an increase in the odds of a sample belonging to the positive
class after being classified as negative. This is the case when the
classifier systematically predicts the opposite of the true label.
A typical application in medicine is to identify the positive/negative class
to the presence/absence of a disease, respectively; the classifier being a
diagnostic test; the pre-test probability of an individual having the
disease can be the prevalence of such disease (proportion of a particular
population found to be affected by a medical condition); and the post-test
probabilities would be the probability that the condition is truly present
given a positive test result.
Estimated targets as returned by a classifier. Sparse matrix is only
supported when targets are of multilabel type.
labels : array-like, default=None
List of labels to index the matrix. This may be used to select the
positive and negative classes with the ordering labels=[negative_class,positive_class]. If None is given, those that appear at least once in
y_true or y_pred are used in sorted order.
sample_weight : array-like of shape (n_samples,), default=None
Sample weights.
replace_undefined_by : np.nan, 1.0, or dict, default=np.nan
Sets the return values for LR+ and LR- when there is a division by zero. Can
take the following values:
np.nan to return np.nan for both LR+ and LR-
1.0 to return the worst possible scores: {"LR+":1.0,"LR-":1.0}
a dict in the format {"LR+":value_1,"LR-":value_2} where the values can
be non-negative floats, np.inf or in the range of the
likelihood ratios. For example, can be used for
returning the worst scores, indicating a useless model, and can be used for returning the best scores, indicating a useful
model.
Returns:
(positive_likelihood_ratio, negative_likelihood_ratio) : tuple of float
A tuple of two floats, the first containing the positive likelihood ratio (LR+)
and the second the negative likelihood ratio (LR-).