Sensitivity + Specificity + PPV + TP/FP/TN/FN Formulas
Formulas for sensitivity, specificity, PPV, NPV, TPR, FPR, prevalence, etc.
A brief cheat sheet / reference guide containing the definitions, formulas, and explanations of the most commonly used model evaluation metrics for binary classification tasks.
Quickstart
Name | Formula | Definition |
---|---|---|
Sensitivity / Recall / Hit Rate / TPR | ||
Specificity / Selectivity / TNR / 1 - FPR | ||
PPV / Precision | ||
NPV | ||
FDR | ||
FPR |
Note: Prevalence impacts PPV/NPV, but does not impact Sensitivity/Specificity/AUROC.
Background
We have a binary classification model .
We have a set of inputs , and a set of corresponding labels .
The goal of our model is to predict the label for a given input.
In other words, given some input , the model makes a binary prediction of 0 or 1. Unknown to our model, the input has an associated ground truth label .
Ideally,
Example
Let’s say that we want to predict whether a patient has a disease or not.
We develop a binary classification model for this task.
We say that if patient has the disease, or if patient does not have the disease.
We say that if the model predicts that patient has the disease, otherwise .
Notation
- = input example
- = set of all inputs
- = set of all ground truth labels
- = total number of inputs
- = the prediction of our model for a specific
- = the ground truth for a specific (i.e. the value we are trying to predict)
- = an indicator function. It evaluates to 1 if the boolean expression inside of it is TRUE; otherwise, it evaluates to 0.
- is referred to as a “negative” true outcome
- is referred to as a “positive” true outcome
- is referred to as a “negative” prediction
- is referred to as a “positive” prediction
Counts (TP / TN / FP / FN)
Name | Definition | Is prediction correct? | Interpretation |
---|---|---|---|
True Positives (TP) | Yes | Number of times your model predicted when | |
True Negatives (TN) | Yes | Number of times your model predicted when | |
False Positives (FP) | No | Number of times your model predicted when | |
False Negatives (FN) | No | Number of times your model predicted that when |
Counts (Ground Truth / Predictions)
Name | Definition | Formula | Interpretation |
---|---|---|---|
Ground Truth Positives () | Number of examples in your dataset where . | ||
Ground Truth Negatives () | Number of examples in your dataset where | ||
Predicted Positives () | Number of times the model predicted | ||
Predicted Negatives () | Number of times the model predicted | ||
Prevalence () | Proportion of examples in your dataset where |
Sensitivity / Specificity
Name | Definition | Formula #1 | Formula #2 | Formula #3 | Interpretation |
---|---|---|---|---|---|
Sensitivity / Recall / Hit Rate / True Positive Rate (TPR) | 5% sensitivity => 5% of positive patients will test positive. | ||||
Specificity / Selectivity / True Negative Rate (TNR) | 5% specificity => 5% of negative patients will test negative. | ||||
False Positive Rate (FPR) | 5% FPR => 5% of patients that are negative will test positive |
Predictive Values
Name | Definition | Formula #1 | Formula #2 | Formula #3 | Interpretation |
---|---|---|---|---|---|
Precision / Positive Predictive Value (PPV) | 5% PPV => 5% of patients that test positive are actually positive | ||||
Negative Predictive Value (NPV) | 5% NPV => 5% of patients that test negative are actually negative | ||||
False Discovery Rate (FDR) | 5% FDR => 5% of patients that test positive are actually negative |
Interpretation
**Sensitivity: **Ability to detect disease if a person has it. (Source)
Specificity: Ability to exclude people without disease. (Source)
PPV: How likely does someone with a positive result have the disease? (Source)
NPV: How likely does someone with a negative result not have the disease? (Source)
When to Use
From Geeky Medics:
Test with high specificity => rule in an outcome when prediction is positive
- If high specificity, then
- Thus, getting a result of probably means that
- Since if then we would have gotten
Test with high sensitivity => rule out an outcome when prediction is negative
- If high sensitivity, then
- Thus, getting a result of probably means that
- Since if then we would have gotten
Prevalence
- Sensitivity and specificity are not impacted by prevalence
- They are metrics of the test, no population
- PPV and NPV are impacted by prevalence
- Higher prevalence -> Higher PPV
- At low prevalence -> We expect NPV > PPV