Dictionary of Applied Machine Learning

accuracy

Updated on 2026-09-11

Typeset PDF version — the authoritative form of this entry

Python demo — a script that recomputes what this entry states and prints one line per check

Accuracy is the fraction of correct predictions made by a hypothesis on a dataset with a finite label space, equal to one minus the average $0/1$ loss. It is widely used as a single-number metric for classification methods. Accuracy is not suitable as an objective function for training, since the $0/1$ loss is non-smooth and non-convex. Empirical risk minimization (ERM) uses a smooth surrogate loss instead, and accuracy is reported during validation. On imbalanced data, a large accuracy can hide failure on the minority class, which calls for other means of evaluation such as the confusion matrix.

Definition

Accuracy is the fraction of correct predictions made by a hypothesis $\hypothesis: \featurespace \rightarrow \labelspace$ on a dataset $\dataset = \big\{ \big(\featurevec^{(\sampleidx)}, \truelabel^{(\sampleidx)} \big) \big\}_{\sampleidx=1}^{\samplesize}$ with a finite label space $\labelspace$ (Goodfellow et al., 2016, Sect. 5.1): \begin{align*} \operatorname{acc}(\hypothesis|\dataset) & \defeq 1 - \frac{1}{\samplesize} \sum_{\sampleidx=1}^{\samplesize} \lossfunczo{\big(\featurevec^{(\sampleidx)}, \truelabel^{(\sampleidx)}\big)}{\hypothesis} \\ & = \frac{1}{\samplesize} \Big| \Big\{ \sampleidx \in \{1, \,\ldots, \,\samplesize\} : \hypothesis\big(\featurevec^{(\sampleidx)}\big) = \truelabel^{(\sampleidx)} \Big\} \Big| \text{.} \end{align*} Accuracy ranges from $0$ (no prediction is correct) to $1$ (every prediction is correct). Equivalently, accuracy equals one minus the average $0/1$ loss on the dataset. For example, in image classification, accuracy is the fraction of images assigned the correct category.

S-linear-classifier-hFig. 1 compares two classifiers on the same dataset. The linear classifier $\hypothesis$ misclassifies three data points near its decision boundary. The nonlinear classifier $\hypothesis'$ curves around each of these data points and classifies them correctly.

Figure 1 of the entry accuracy
Figure 1: Two classifiers applied to the same $\samplesize=60$ data points with classes $\truelabel \in \{0,1\}$. The linear classifier $\hypothesis$ (dashed) places three data points on the wrong side of its decision boundary, yielding $\operatorname{acc}(\hypothesis|\dataset) = 57/60 = 0.95$. The nonlinear classifier $\hypothesis'$ (solid green) curves around those three data points and yields $\operatorname{acc}(\hypothesis'|\dataset) = 1$. Data generated by pythondemos/accuracy.py
The classifier $\hypothesis'$ in Fig. 1 achieves the optimal accuracy of $1$ on $\dataset$: its decision boundary closely follows the positions of the individual data points that the linear classifier misclassifies. As a result, $\hypothesis'$ is sensitive to small perturbations of the feature vectors, such as measurement noise. A slight shift in the feature vector of a data point near the decision boundary can flip the prediction. Optimizing accuracy on the training set therefore does not by itself ensure good generalization.

While accuracy is often used to compare learned classifiers on a validation set or a test set, it is not suitable as an objective function for training. Indeed, accuracy is defined via the $0/1$ loss, which is non-smooth and non-convex. Gradient-based optimization methods cannot maximize accuracy directly. Instead, training methods for classifiers, e.g., via empirical risk minimization (ERM), typically use a surrogate loss that approximates the $0/1$ loss. Two widely used examples for such a surrogate loss are the logistic loss, which is convex and differentiable, and the hinge loss, which is convex but not differentiable. Fig. 2 shows the three loss functions for binary classification with $\labelspace = \{-1, 1\}$, where a real-valued hypothesis $\hypothesis$ predicts via the sign of $\hypothesis(\featurevec)$. Each loss function depends on the data point only through the product $\truelabel \cdot \hypothesis(\featurevec)$.

Figure 2 of the entry accuracy
Figure 2: Three loss functions for binary classification as functions of the product $\truelabel \cdot \hypothesis(\featurevec)$. The hinge loss and logistic loss are convex upper bounds on the $0/1$ loss
Accuracy can also be misleading for imbalanced data. Consider a frost warning for Krems an der Donau (Austria): the features of a data point are the minimum and the maximum air temperature of one day, and its label indicates whether the minimum temperature of the following day falls below $0\,^{\circ}\mathrm{C}$. Frost days are the minority class: only $6$ of $40$ recorded days are followed by frost. The constant prediction "above zero" (a baseline that ignores the features) is therefore correct on $34$ of the $40$ days, an accuracy of $0.85$, and a classifier learned by logistic regression from the $40$ data points reaches the same accuracy of $0.85$. Accuracy cannot tell the two apart, which calls for other means of evaluation such as the confusion matrix. The confusion matrices in Fig. 3 show that the learned classifier detects one of the six frost days while the baseline detects none.
Figure 3 of the entry accuracy
Figure 3: The confusion matrices of the frost-warning classifier learned by logistic regression and of the always-above-zero baseline. Both reach an accuracy of $0.85$; only the confusion matrices show that the learned classifier detects one frost day and raises one false alarm, while the baseline detects none. Data generated by pythondemos/cm.py
See also: $0/1$ loss, loss, classification, F$_1$ score, confusion matrix, imbalanced data.

References

  1. Goodfellow et al. (2016). Deep Learning. MIT Press.

Cite this entry

@misc{dictml_accuracy,
  author = {Jung, Alexander and Olioumtsevits, Konstantina and Schnoor, Ekkehard},
  title = {accuracy},
  howpublished = {Dictionary of Applied Machine Learning (course edition)},
  year = {2026},
  doi = {10.5281/zenodo.21569296},
  note = {ISBN 978-952-64-3013-3, CC BY 4.0, retrieved 2026-09-11},
  url = {https://dictionaryofml.org/terms/accuracy.html}
}