How to Calculate True Positive Rate From Confusion Matrix
The true positive rate (TPR), also known as sensitivity or recall, is a crucial metric in machine learning and statistical analysis. It measures the proportion of actual positives that are correctly identified by a test or model. This guide explains how to calculate TPR from a confusion matrix, provides an interactive calculator, and offers practical interpretation.
What is True Positive Rate?
The true positive rate (TPR) is a performance metric that answers the question: "Of all the actual positive cases, how many did we correctly identify?" In medical testing, this would mean the proportion of people who actually have a disease that the test correctly identifies as having the disease.
TPR is calculated as the ratio of true positives (correctly identified positive cases) to the sum of true positives and false negatives (actual positive cases that were missed).
Key Points:
- TPR ranges from 0 to 1, with higher values indicating better performance
- A TPR of 1 means all positive cases were correctly identified
- TPR is complementary to the false positive rate (FPR)
- High TPR is generally desirable, but must be balanced with other metrics
Confusion Matrix Basics
A confusion matrix is a table that describes the performance of a classification model by showing the counts of correct and incorrect predictions. It has four components:
| Actual\Predicted | Positive | Negative |
|---|---|---|
| Positive | True Positive (TP) | False Negative (FN) |
| Negative | False Positive (FP) | True Negative (TN) |
For our TPR calculation, we focus on the true positives (TP) and false negatives (FN) from this matrix.
How to Calculate True Positive Rate
The formula for true positive rate is straightforward:
True Positive Rate (TPR) = TP / (TP + FN)
Where:
- TP = True Positives (correctly identified positive cases)
- FN = False Negatives (actual positive cases incorrectly identified as negative)
The result is typically expressed as a decimal between 0 and 1, or as a percentage when multiplied by 100.
Important Notes:
- TPR is also known as sensitivity or recall in some contexts
- It measures the model's ability to identify positive cases
- A high TPR doesn't account for false positives, so it should be considered with other metrics
Example Calculation
Let's walk through an example to make this concrete. Suppose we have a medical test for a disease with the following confusion matrix:
| Actual\Predicted | Positive | Negative |
|---|---|---|
| Positive | 80 (TP) | 20 (FN) |
| Negative | 10 (FP) | 90 (TN) |
To calculate the TPR:
- Identify TP and FN from the matrix: TP = 80, FN = 20
- Plug these values into the formula: TPR = 80 / (80 + 20) = 80 / 100 = 0.8
- Convert to percentage if needed: 0.8 × 100 = 80%
This means the test correctly identified 80% of all actual positive cases.
Interpreting the Result
Interpreting the true positive rate requires considering several factors:
- Context: A TPR of 0.8 might be excellent for some applications but poor for others
- Comparison: Compare with other models or benchmarks to assess performance
- Trade-offs: High TPR often comes with higher false positive rates
- Thresholds: Adjusting classification thresholds can affect TPR
In our example, a TPR of 80% suggests the test is quite effective at identifying positive cases, but we should also consider the false positive rate (10% of negative cases incorrectly identified as positive).
Frequently Asked Questions
What's the difference between true positive rate and accuracy?
Accuracy measures overall correctness (TP + TN)/(TP + TN + FP + FN), while TPR focuses specifically on correctly identifying positive cases. A model could have high accuracy but low TPR if it's very conservative about positive predictions.
How does true positive rate relate to false positive rate?
TPR and FPR are complementary metrics. TPR measures how well positive cases are identified, while FPR measures how often negative cases are incorrectly identified as positive. Together, they provide a more complete picture of model performance.
Can true positive rate be higher than 1?
No, TPR cannot exceed 1 because it's a ratio of correctly identified positives to all actual positives. A value of 1 means all positive cases were correctly identified, while a value of 0 means none were correctly identified.