Processing math: 100%

Micro-average == Weighted Macro-average

Common classification problems in Machine Learning (ML) are binary and multi-class (Sokolova and Lapalme, 2009). For binary classification, we have accuracy, precision, recall, and a combination of precision and recall which is so-called F1 score. However, the precision and recall from binary classification cannot be utilized literally to measure multi-class classification.

To measure the performance of multi-class classification, two important modifications on precision and recall of binary classification are introduced. Their names are macro-average and micro-average. Therefore, for example, the precision of multi-class classification shall become macro-average precision and micro-average precision.

Let’s begin with an example of multi-class classification with 4 classes (0, 1, 2, and 3). Suppose we have our predictions and the true labels for five data instances as follows:

our predictions=[0,0,2,2,3],true labels=[0,1,3,3,3]

Our first prediction is 0 and the true label is 0. Next, our second prediction is 0 and the true label is 1. Our third prediction is 2 while the true label is 3 and so on. Let’s denote

tpi=true positive for class i(i=0,1,2,3),fpi=false positive for class i(i=0,1,2,3).

After counting the true and false positives for each class, we obtain

tp0=1,tp1=0,tp2=0,tp3=1, andfp0=1,fp1=0,fp2=2,fp3=0.

As we’ve already known, precision for class i (precisioni) is defined as follows:

precisioni=tpitpi+fpi, for i=0,1,2,3.

Therefore, employing Equation (1), we get

precision0=0.5,precision1=0,precision2=0,precision3=1.

As explained in “Micro Average vs Macro average Performance in a Multiclass classification setting”, the macro-average precision (precisionM) for 4 classes is defined as

precisionM=3i=0precisioni4=0.5+0+0+14=0.375.

However, the micro-average precision (precisionμ) for 4 classes is defined as

precisionμ=3i=0tpi3i=0(tpi+fpi)=1+0+0+12+0+2+1=0.4.

If there is a class imbalance problem, one of the options will be using weighted macro-average as performance metrics. The weighted macro-average precision (precisionWM) for 4 classes is defined as

precisionWM=3i=0weighti×precisioni

with weighti is the weight assigned to class i as follows:

weighti=tpi+fpi3i=0(tpi+fpi)

Using Equation (3) and (4), we compute the weighted macro-average precision as follows:

precisionWM=25×0.5+0×0+25×0+15×1=0.4.

Next, we shall show that the weighted macro-average precision does equal to the micro-average precision.

precisionWM=3i=0weighti×precisioni=3i=0tpi+fpi3i=0(tpi+fpi)×tpitpi+fpi=3i=0tpi+fpi3i=0(tpi+fpi)×tpitpi+fpi=3i=0tpi3i=0(tpi+fpi)=3i=0tpi3i=0(tpi+fpi)=precisionμ.

Finally we have reached the end of this post. In brief, we have shown how to compute macro-average, micro-average, and weighted macro-average. Moreover, we have also shown that the micro-average equals to weighted macro-average.


References

Sokolova, M. and Lapalme, G. (2009). A systematic analysis of performance measures for classification tasks. Information Processing & Management, 45(4):427 - 437.


Written on August 1, 2020