Calculate classification accuracy from correct predictions and total samples.
Accuracy is the fraction of all predictions that were correct: accuracy = (TP + TN) / (TP + TN + FP + FN). It's the most intuitive classification metric, but it can be misleading on imbalanced datasets — a classifier that always predicts the majority class can score high accuracy while completely failing the minority class. For imbalanced problems, precision, recall, F1, or balanced accuracy usually give a more honest picture of performance.
accuracy = (TP + TN) / (TP + TN + FP + FN)
On imbalanced datasets, a model can achieve high accuracy simply by always predicting the majority class, while providing no real predictive value for the minority class. In those cases, precision, recall, F1, or balanced accuracy are more informative.
It depends entirely on the task and class balance. 95% accuracy is unremarkable on a dataset that's 95% one class, but excellent on a balanced, hard classification problem — always compare against a naive baseline.
Accuracy measures overall correctness across both classes, while precision measures correctness only among the predictions labeled positive — precision ignores true negatives entirely.