Accuracy measures

22 Dec 2017
Gonzalo Mateo-García

The confusion matrix $(i,j)$-element is the number of samples known to be $i$ that are predicted $j$. When the problem is binary the confusion matrix is $2 \times 2$ and its elements are normally represented in a table like the following:

    Predicted   Total
Real   0 1  
  0 TN FP $N$
  1 FN TP $P$
Total   $\hat{N}$ $\hat{P}$ total

Basic values

Added values

We compute them by adding by rows or cols in the confusion matrix:

Rates

\[PR = \frac{P}{\text{total}} = \frac{P}{P+N}\] \[NR = \frac{N}{\text{total}} = \frac{N}{P+N} = 1-PR\] \[TPR = \frac{TP}{P} = \frac{TP}{TP + FN}\] \[FPR = \frac{FP}{N} = \frac{FP}{FP + TN}\] \[FNR = \frac{FN}{P} = \frac{FN}{TP + FN} = 1 - TPR\] \[TNR = \frac{TN}{N} = \frac{TN}{TN + FP} = 1 - FPR\] \[\text{Precision} = \frac{TP}{\hat{P}} = \frac{TP}{FP + TP}\] \[\begin{aligned} \text{Accuracy} &= \frac{TP+TN}{total} = \frac{TP+TN}{TN+FP+FN+TP} \\ &= \frac{TP}{P}\frac{P}{total}+\frac{TN}{N}\frac{N}{total} = TPR \cdot PR + TNR \cdot (1-PR) = TPR \cdot PR + (1-FPR) \cdot (1-PR) \end{aligned}\] \[F_1 = \frac{2}{\tfrac{1}{\text{recall}} + \tfrac{1}{\text{precision}}}\]