Precision From a Confusion Matrix: Formula and Example
- Predicted positives
- count
- Result
- True positives
- 40
- You entered
- False positives
- 10
- You entered
Precision from a confusion matrix is true positives divided by all predicted positives: TP / (TP + FP). Enter the true-positive and false-positive counts below to calculate the share of positive predictions that were correct, along with the total number of positive predictions.
Formula
Precision = TP / (TP + FP), or Precision (%) = TP / (TP + FP) × 100.
- TP means true positives: cases the model predicted as positive that actually are positive.
- FP means false positives: cases the model predicted as positive that actually are negative.
- TP + FP is the total number of positive predictions.
The calculator’s first result is precision as a percentage. Its second result is the count of predicted positives. Counts are unitless and should be nonnegative whole numbers. If TP + FP is zero, precision is undefined: there are no positive predictions to assess, so the formula would divide by zero.
Worked Example
Using the default values, TP = 40 and FP = 10:
- Add the positive predictions: TP + FP = 40 + 10 = 50.
- Divide the true positives by that total: 40 / 50 = 0.8.
- Convert the proportion to a percentage: 0.8 × 100 = 80.00%.
There are 50 predicted positives, of which 40 are correct. The calculator therefore returns precision of 80.00% and 50 predicted positives.
What Precision Tells You
Precision answers: “Of the cases classified as positive, what fraction really were positive?” A precision of 80% means that, among the positive predictions counted in the matrix, 80% were true positives and 20% were false positives. It does not mean that 80% of all cases were classified correctly.
This measure is useful when false alarms matter. For example, in a system that flags transactions for review, higher precision means a larger share of flagged transactions are genuinely positive cases under the chosen definition. Whether that is desirable depends on the costs of false positives and missed positives, and on how the positive class is defined.
Precision is also called positive predictive value in some fields. The underlying calculation is the same, though terminology and conventions can vary by application. Always identify which class counts as “positive” before interpreting a result.
Precision Compared With Recall and Accuracy
Precision is easy to confuse with other measures derived from a confusion matrix. They use overlapping counts but answer different questions:
- Recall (also called sensitivity or true-positive rate) = TP / (TP + FN). It measures how many actual positives the model found.
- Accuracy = (TP + TN) / (TP + TN + FP + FN). It measures the share of all predictions that are correct.
- F1 score = 2 × (precision × recall) / (precision + recall). It combines precision and recall as their harmonic mean.
Here, FN means false negatives and TN means true negatives. A model can have high precision but low recall if it makes only a few positive predictions and misses many actual positives. Conversely, it can achieve high recall while also producing many false positives, lowering precision. No single measure gives the whole picture.
How to Get the Counts and Avoid Mistakes
A confusion matrix compares predicted labels with actual labels. For a binary classifier, first decide which label is positive, then identify the true-positive and false-positive cells. Matrix layouts vary: some put actual labels in rows and others put them in columns, so read the row and column headings rather than assuming a fixed position.
- Use counts from the same evaluation set and the same classification threshold.
- Include only cases that received a positive prediction in the denominator, TP + FP. Do not add false negatives or true negatives to it.
- Check that TP and FP are counts, not percentages or values from different datasets.
- Keep sufficient precision during calculation, then round the final percentage for display. For example, 1 / 3 is 33.333…%, not exactly 33%.
- If the positive prediction count is zero, report precision as undefined or not applicable rather than forcing it to zero.
A common error is to divide TP by all actual positives, TP + FN. That is recall, not precision. Another is to interpret a high precision score as evidence that most actual positive cases were found; that conclusion requires recall information as well.
Limits and Interpreting Results
Precision depends on the model’s decisions and on the data being evaluated. Changing a classification threshold can change TP and FP, and therefore precision. The score can also change when the proportion of positive cases in the evaluated population changes, even if the classifier’s behavior in other respects is similar. When comparing models, use the same definitions, evaluation data, and threshold where appropriate.
A percentage alone does not show how much evidence supports it. Precision of 100% based on one positive prediction is less informative than 100% based on thousands of predictions. Report the counts alongside the score, and consider uncertainty when the sample is small. For multiclass problems, calculate precision separately for each class by treating that class as positive and the others as negative; a macro or weighted average may summarize the class-level results, but the averaging method should be stated.
Frequently Asked Questions
Can precision be calculated from accuracy alone?
No. Accuracy combines correct positive and negative predictions, while precision needs TP and FP. Different confusion matrices can have the same accuracy but different precision.
What does 100% precision mean?
It means FP is zero among the evaluated positive predictions, so every predicted positive was a true positive. It does not show how many actual positives were missed; check recall for that.
What if the confusion matrix has no predicted positives?
Then TP + FP = 0 and precision is undefined because the denominator is zero. State that there were no positive predictions rather than presenting a misleading percentage.
Is precision the same as positive predictive value?
Yes. Positive predictive value is another name for TP / (TP + FP), though the preferred term depends on the field.
How do you calculate precision for multiple classes?
For each class, treat it as the positive class and all other classes as negative, then calculate TP / (TP + FP). If combining results, specify whether the average is macro, weighted, or micro, since these can produce different values.
Related
Formula used
in tp | True positives | - | 40 | 0 in fp | False positives | - | 10 | 0 out precision | Precision | % | tp / (tp + fp) * 100 | 2 out predicted | Predicted positives | count | tp + fp | 0
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.