Generalized Confusion Matrix for Multiple Classes Garillos-Manliguez, C.A.
[email protected] November 25, 2016
This document was made due to the lack of resources to reference for confusion matrix with multiple classes and no generalized formulae are used for calculating the precision, recall, specificity, and overall accuracy of the system having many classes to consider. The following table shows a sample format of a confusion matrix with n classes:
Actual Number
Predicted Number Class 1
Class 2
…
Class n
Class 1
𝑥11
𝑥12
…
𝑥1𝑛
Class 2
𝑥21
𝑥22
…
𝑥2𝑛
. . .
. . .
. . .
. . .
. . .
Class n
𝑥𝑛1
𝑥𝑛2
…
𝑥𝑛𝑛
The total numbers of false negative (TFN), false positive (TFP), and true negative (TTN) for each class i will be calculated based on the Generalized Equations 1, 2, and 3, respectively. The total true positive in the system will be obtained through Equation 4. 𝑛
𝑇𝐹𝑁𝑖 = ∑ 𝑥𝑖𝑗 𝑗=1 𝑗≠ 𝑖 𝑛
𝑇𝐹𝑃𝑖 = ∑ 𝑥𝑗𝑖 𝑗=1 𝑗≠ 𝑖 𝑛 𝑛
𝑇𝑇𝑁𝑖 = ∑ ∑ 𝑥𝑗𝑘 𝑗=1 𝑘=1 𝑗≠ 𝑖 𝑘≠𝑖
[1]
[2]
[3]
𝑛
𝑇𝑇𝑃𝑎𝑙𝑙 = ∑ 𝑥𝑗𝑗
[4]
𝑗=1
To compute the generalized precision (P), recall (R), and specificity(S) for each class i Generalized Equations 5, 6, and 7 will be used. 𝑃𝑖 =
𝑇𝑇𝑃𝑎𝑙𝑙 𝑇𝑇𝑃𝑎𝑙𝑙 + 𝑇𝐹𝑃𝑖
[5]
𝑅𝑖 =
𝑇𝑇𝑃𝑎𝑙𝑙 𝑇𝑇𝑃𝑎𝑙𝑙 + 𝑇𝐹𝑁𝑖
[6]
𝑆𝑖 =
𝑇𝑇𝑁𝑎𝑙𝑙 𝑇𝑇𝑁𝑎𝑙𝑙 + 𝑇𝐹𝑃𝑖
[7]
𝑇𝑇𝑃𝑎𝑙𝑙 𝑇𝑜𝑡𝑎𝑙 𝑁𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑇𝑒𝑠𝑡𝑖𝑛𝑔 𝐸𝑛𝑡𝑟𝑖𝑒𝑠
[8]
𝑂𝑉𝐸𝑅𝐴𝐿𝐿 𝐴𝐶𝐶𝑈𝑅𝐴𝐶𝑌 =