Accuracy
Accuracy is the share of predictions a model gets right. Formula, top-1 and top-5 accuracy, the accuracy paradox on imbalanced data, and better metrics.
Accuracy is the fraction of a model's predictions that are correct: the number of correct predictions divided by the total number of predictions. It is the default score for image classification and other supervised learning tasks with one label per input, and it answers the plainest question about a model, how often it is right. Accuracy is easy to read and compare across models, but it weighs every prediction equally, so on imbalanced data a model can score high while failing on exactly the cases that matter.
How Accuracy Is Calculated#
For a binary task, the four counts of a confusion matrix give accuracy = (TP + TN) / (TP + TN + FP + FN): true positives plus true negatives over all predictions. For a task with many classes, accuracy is the sum of the matrix diagonal over the total count, and scikit-learn's accuracy_score computes it directly from two arrays of labels. Accuracy is often reported as an error rate instead, where error = 1 − accuracy.
Top-1 and Top-5 Accuracy#
Classifiers with many classes also report top-k accuracy. Top-1 accuracy counts a prediction as correct only when the highest-scoring class is the true label, and top-5 accuracy counts it as correct when the true label is anywhere among the five highest-scoring classes. Top-5 became standard with the ImageNet challenge, whose photos often contain several objects but carry a single label from 1,000 classes. YOLO26 classification models report both numbers, and the nano model, yolo26n-cls.pt, reaches 71.4% top-1 and 90.1% top-5 accuracy on ImageNet at 224 pixels.
Accuracy vs. Related Metrics#
- Precision: of the predicted positives, the share that are truly positive. It rises as false alarms fall.
- Recall: of the actual positives, the share the model finds. It is the number that exposes a model that ignores a rare class.
- F1-score: the harmonic mean of precision and recall, which stays low unless both are high.
- Mean average precision (mAP): the standard metric for object detection, where accuracy does not apply because the background offers no countable true negatives, only an unlimited number of empty image regions.
The Accuracy Paradox#
When one class dominates, accuracy rewards ignoring the rare class. If 1% of transactions are fraudulent, a model that approves every transaction is 99% accurate and catches no fraud at all, a pattern known as the accuracy paradox. The same trap appears in defect inspection, disease screening, and anomaly detection, where the class of interest is rare by nature.
import numpy as np
from sklearn.metrics import accuracy_score, balanced_accuracy_score, recall_score
# 1,000 transactions, 10 of them fraudulent (label 1)
y_true = np.zeros(1000, dtype=int)
y_true[:10] = 1
# A model that labels every transaction as legitimate
y_pred = np.zeros(1000, dtype=int)
print(f"Accuracy: {accuracy_score(y_true, y_pred):.2f}")
print(f"Balanced accuracy: {balanced_accuracy_score(y_true, y_pred):.2f}")
print(f"Fraud recall: {recall_score(y_true, y_pred):.2f}")Balanced accuracy, the mean recall across classes, exposes the failure that plain accuracy hides: the script prints an accuracy of 0.99, a balanced accuracy of 0.50, and a fraud recall of 0.00.










