What is the difference between micro and macro averaging?

Introduction

Micro average is concerned with the study of individual classes. For example, a firm’s micro average examines personal goods’ price and market structure.

Macro average is concerned with aggregations or totals. We study economy-wide phenomena such as unemployment, price levels of economic growth, and gross domestic product or GDP using macro average.

The difference between macro and micro averaging is that macro averaging gives equal weight to each category while micro averaging gives equal weight to each sample. If we have the same number of samples for each class, both macro and micro will provide the same score.

Calculation of micro and macro averaging

Let's suppose we have a multi-class classification system with three unbalanced classes. Here is the possible confusion matrix for these classes.

Confusion Matrix



Predicted

Classes

Actual

X

Y

Z

X

10

2

3

Y

1

8

2

Z

2

3

9

Next, the following table shows each class's metrics values (TP, FP, FN) and performance measures (Precision, Recall) values for the above confusion matrix.


Class

True Positive (TP)

False Positive (FP)

False Negitive (FN)


Precision


Recall

X

10

2

3

0.77

0.67

Y

8

1

2

0.62

0.73

Z

9

2

3

0.64

0.64

Micro average precision

The micro average precision is the sum of all true positives divided by the sum of all true positives and false positives. In other words, we divide the number of correctly identified predictions by the total number of predictions. The micro average calculation of the data above would be as follows:

PrecisionMicroAvg =(𝑇𝑃1+𝑇𝑃2++𝑇𝑃𝑛)(𝑇𝑃1+𝑇𝑃2++𝑇𝑃𝑛+𝐹𝑃1+𝐹𝑃2++𝐹𝑃𝑛)= \frac{(𝑇𝑃_1 + 𝑇𝑃_2 + … + 𝑇𝑃_𝑛)}{(𝑇𝑃_1+𝑇𝑃_2+ … + 𝑇𝑃_𝑛 + 𝐹𝑃_1 + 𝐹𝑃_2 + … + 𝐹𝑃_𝑛)}

PrecisionMicroAvg =(10+8+9)(10+8+9+2+1+2)=(27)(32)=0.84= \frac{(10 + 8 + 9)}{(10 + 8 + 9 + 2 + 1 + 2)} = \frac{(27)}{(32)} = 0.84

Macro average precision

The macro average precision is the arithmetic mean of all the precision values for the different classes. The macro average calculation of the data above would be as follows:

PrecisionMacroAvg =(𝑃𝑟𝑒𝑐1+𝑃𝑟𝑒𝑐2++𝑃𝑟𝑒𝑐𝑛)n= \frac{(𝑃𝑟𝑒𝑐_1+𝑃𝑟𝑒𝑐_2+…+𝑃𝑟𝑒𝑐_𝑛)}{n}

PrecisionMacroAvg =(0.77+0.62+0.64)(3)=(2.03)(3)=0.677= \frac{(0.77 + 0.62 + 0.64)}{(3)} = \frac{(2.03)}{(3)} = 0.677

Micro average recall

The micro average recall is the sum of true positives for all classes divided by actual positives (rather than predicted positives). The micro average calculation of the data above would be as follows:

RecallMicroAvg =(𝑇𝑃1+𝑇𝑃2++𝑇𝑃𝑛)(𝑇𝑃1+𝑇𝑃2++𝑇𝑃𝑛+𝐹N1+𝐹N2++𝐹N𝑛)= \frac{(𝑇𝑃_1 + 𝑇𝑃_2 + … + 𝑇𝑃_𝑛)}{(𝑇𝑃_1+𝑇𝑃_2+ … + 𝑇𝑃_𝑛 + 𝐹N_1 + 𝐹N_2 + … + 𝐹N_𝑛)}

RecallMicroAvg =(10+8+9)(10+8+9+3+2+3)=(25)(40)=0.625= \frac{(10 + 8 + 9)}{(10 + 8 + 9 + 3 + 2 + 3)} = \frac{(25)}{(40)} = 0.625

Macro average recall

The macro average recall is the arithmetic mean of all recall scores for different classes. The macro average calculation of the data above would be as follows:

RecallMacroAvg =(Recall1+Recall2++Recall𝑛)n= \frac{(Recall_1+Recall_2+…+Recall_𝑛)}{n}

RecallMacroAvg =(0.67+0.73+0.64)(3)=(2.04)(3)=0.68= \frac{(0.67 + 0.73 + 0.64)}{(3)} = \frac{(2.04)}{(3)} = 0.68

Conclusion

Here is what we can infer about micro and macro averages:

Micro averaging
  • Micro average statistics evaluate models trained for multi-class classification problems.

  • We use micro averaging when we need an equal weight for each instance or prediction.

  • The micro average precision is the sum of true positives for a single class divided by the sum of predicted positives for all classes.

  • The micro average recall score is the sum of true positives for a single class divided by the sum of true positives for all classes.

Macro averaging
  • Macro average statistics evaluate models trained for multi-class classification problems.

  • We use macro averaging in case of a class unbalance (different number of instances associated with different class labels).

  • The macro average is the arithmetic mean of the individual class related to precision, memory, and f1 score.

  • We use macro average scores when we need to treat all classes equally to evaluate the overall performance of the classifier against the most common class labels.

Copyright ©2024 Educative, Inc. All rights reserved