Accuracy Calculator
Free accuracy calculator. Find accuracy from a confusion matrix (with sensitivity, specificity, precision and F1), adjust for prevalence, or get percent accuracy from percent error.
https://hexacalculator.com/calculators/mathematics/statistics/accuracy-calculator
Mathematics
Statistics
Accuracy Calculator
Free accuracy calculator. Find accuracy from a confusion matrix (with sensitivity, specificity, precision and F1), adjust for prevalence, or get percent accuracy from percent error.
Accuracy Calculator
Accuracy method
Confusion matrix
Enter the four counts from your test. Rows are what the test predicted, columns are the truth: TP and FP were called positive; FN and TN were called negative.
Result
%
%
%
A fair result. Whether it is good enough depends on the cost of the errors it still makes.
- Balanced accuracy
- %
- Precision (PPV)
- %
- F1 score
- Error rate
- %
- Prevalence in sample
- %
- Total cases
Metric comparison
Accuracy describes how close the results are to the actual situation. This calculator provides three different methods. The specific meaning of "accuracy" varies depending on whether it is a data scientist testing a classifier, an epidemiologist assessing medical tests, or a chemist verifying measurements.
By selecting a method above the corresponding input fields will be adapted. For the confusion matrix method also a set of classification metrics including sensitivity, specificity, precision and f1-score are shown at the same time.
Three methods and their fields of application:
The correct choice of method is the most important step. There are simple rules of thumb in diagnostics.
Method | Use it when | You need |
|---|---|---|
Confusion matrix | You have raw counts and the sample reflects real prevalence | TP, TN, FP, FN |
Sensitivity & specificity | Your sample does not reflect real prevalence (e.g. a case-control study) | Sensitivity, specificity, true prevalence |
Percent error | You are comparing one measurement with a known true value | Observed value, accepted value |
Method 1: Calculate accuracy from confusion matrix.
A confusion matrix classifies individual predictions into four outcomes. True positives and true negatives indicate that the test was correct while false positives and false negatives show that the test was incorrect. Accuracy is the proportion of cases in which the prediction was correct.
In a study of a population group the following results were achieved: 90 people had a true positive result, 85 people had a true negative result, 15 people had a false-positive result and 10 people had a false-negative result. The hit rate is (90 + 85) / 200 = 0.875, which means 87.5%.
From these four values other metrics can be derived that are not so easily seen from the pure accuracy. Sensitivity (also known as Recall) is the proportion of actual positives which were correctly identified. Specificity is the proportion of actual negatives which were correctly identified. The precision value is the proportion of positive identifications which actually are correct.
Metric | Formula | From the example |
|---|---|---|
Sensitivity (recall) | TP / (TP + FN) | 90 / 100 = 90% |
Specificity | TN / (TN + FP) | 85 / 100 = 85% |
Precision (PPV) | TP / (TP + FP) | 90 / 105 = 85.7% |
F1 score | 2 x P x R / (P + R) | 0.878 |
Balanced accuracy | (Sensitivity + Specificity) / 2 | (90% + 85%) / 2 = 87.5% |
Error rate | (FP + FN) / total | 25 / 200 = 12.5% |
The F1 score is the harmonic mean of precision and recall, and will only be high if both metrics are high. This should be considered especially for very small classes.
Method 2: Adjusting accuracy based on prevalence
Sensitivity and specificity are properties of the test itself and do not change with prevalence, whereas accuracy varies. Even if a test is validated on a sample that has 50/50 ratio of positive and negative results, very low prevalence of disease in actual population will mean that the originally determined accuracy in the sample overestimates the true performance.
The solution is to weight these two ratios according to the actual prevalence of the condition in question.
If a test has sensitivity of 80%, specificity of 90% and the prevalence of the condition being tested for in the population is 10%, then the proportion of correct test results is 0.80 x 0.10 + 0.90 x 0.90 = 0.89, or 89%. You can directly derive sensitivity and specificity from the confusion matrix by turning on the corresponding switch.
Method 3: Percentage Error and Accuracy
For a single measurement, accuracy is how close the measured value is to a known reference value. The percent error is the ratio of this discrepancy to the reference value.
Accuracy is the result when you subtract percent error from 100%.
Suppose a thermometer reads exactly 95 degrees when the actual temperature is 98.7 degrees. The percent error is |95 - 98.7| / 98.7 x 100 = 3.75%, so the reading is 96.25% accurate. The greater the error, the less accurate the measurement.
Accuracy and precision.
These two concepts must not be confused. Accuracy refers to how close a measurement is to the true value, while precision indicates how similar repeated measurements are to each other.
A scale that always displays a value two kilograms heavier than the true weight has high precision, but low accuracy. Another scale shows values that are scattered around the true weight and averages out to be correct on average, but is not precise. In classification tasks, "precision" has a different meaning: it gives the proportion of correctly identified positive results among all identified positive results.
How to correctly interpret results:
Just because a model has high accuracy doesn't necessarily mean it's good. In some cases, even a simple classifier that always predicts the majority class can achieve over 95% accuracy, but miss all of the really important cases.
For this reason, this calculator shows both the accuracy and the balanced accuracy, sensitivity, precision, and F1 score at the same time, and gives a warning if there are significant imbalances in the data. When assessing a study, it is important to consider what types of errors are being made, rather than just relying on one overall value that stands out.
The balanced accuracy is a direct way to deal with imbalances in the data. It computes the average of sensitivity and specificity giving equal weight to all classes. When the data are nearly balanced, both accuracies will be relatively close together. If there is a significant difference between them, normal accuracy often appears inflated while the balanced accuracy more accurately reflects performance.
This tool is for learning and analysis purposes only. The classification metrics are based on the assumption that the input values are correct and independent of each other. In clinical decision making, accuracy must be weighed against the cost of false positives and false negatives.
Frequently asked questions
- How to calculate accuracy from a confusion matrix?
Add the number of correct predictions and divide by the total: Accuracy = (TP + TN) / (TP + TN + FP + FN). For example, if there are 90 true positives, 85 true negatives, and a total of 200, then accuracy is (90+85)/200 = 87.5%. This calculator also computes sensitivity, specificity, precision, and F1 score from these four values.
- What is the difference between accuracy and precision?
Accuracy refers to how close a measurement is to the actual value, while precision indicates how similar multiple measurements are to each other. A scale that always shows two kilograms more than the actual weight has high precision but low accuracy. In the context of classification tasks, precision has a different meaning: it is the proportion of true positive results among predicted positive results, i.e., TP / (TP + FP).
- When should you adjust accuracy based on prevalence?
If the proportion of positive and negative results in a sample does not match the actual prevalence in the population, then the prevalence method should be used. An example is when there are equal numbers of people in the case group and control group in a case-control study. The sensitivity and specificity remain unchanged but the overall accuracy changes depending on how common the condition being tested for is within the population: Accuracy = Sensitivity x Prevalence + Specificity x (1 - Prevalence).
- How do you calculate percent accuracy from percent error?
The percent accuracy is equal to 100% minus the percent error. The percent error is calculated as: |measured value - accepted value| / |accepted value| * 100%. If the measured value is 95 and the accepted value is 98.7, then the percent error is 3.75%, which corresponds to a percent accuracy of 96.25%.
- Why can accuracy be misleading with unbalanced data?
If a class is very rare, then a model that always predicts the majority class can still achieve a very high accuracy but will miss all of the important cases. If only 1% of people have a disease, predicting "no disease" for everyone would result in 99% accuracy, which would be completely useless. It's important to also consider sensitivity, precision and F1 score. This calculator shows these metrics along with accuracy.
- What is Balanced Accuracy and how does it differ from regular accuracy?
The balanced accuracy which is the average of sensitivity and specificity is calculated by the formula: (Sensitivity + Specificity) / 2. As both positive and negative class are given equal weightage, it cannot be misleading due to class imbalance unlike regular accuracy. When the sample is almost balanced, both values will be relatively close to each other. When both values differ significantly, the regular accuracy often appears inflated because of majority class while the balanced accuracy gives a more realistic picture. In this confusion matrix method, both results are shown side by side.
Related calculators






Disclaimer: This calculator is provided for general informational and educational purposes only. Our calculators are under active development, and results may be inaccurate, incomplete, or unsuitable for your situation. Always verify the figures independently and seek advice from a qualified professional before relying on them. We make no warranties and accept no liability for any loss or decision arising from use of this tool.
References
- Wikipedia: Confusion matrix
Definitions of TP/TN/FP/FN and the metrics derived from them.
- Wikipedia: Sensitivity and specificity
How sensitivity, specificity and prevalence combine into accuracy.
- Wikipedia: Accuracy and precision
The distinction between accuracy and precision, and percent error.