Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

What is the difference between micro and macro averaging?

Arslan Tariq

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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 and the following numbers:


Class

True Positive (TP)

False Positive (FP)

False Negitive (FN)


Precision


Recall

X

15

11

2

0.57

0.88

Y

10

90

7

0.1

0.58

Z

5

2

1

0.71

0.83

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 =(15+10+5)(15+10+5+11+90+2)=(30)(133)=0.22= \frac{(15 + 10 + 5)}{(15 + 10 + 5 + 11 + 90 + 2)} = \frac{(30)}{(133)} = 0.22

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.57+0.1+0.71)(3)=(1.38)(3)=0.46= \frac{(0.57 + 0.1 + 0.71)}{(3)} = \frac{(1.38)}{(3)} = 0.46

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 =(15+10+5)(15+10+5+2+7+1)=(30)(40)=0.75= \frac{(15 + 10 + 5)}{(15 + 10 + 5 + 2 + 7 + 1)} = \frac{(30)}{(40)} = 0.75

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.88+0.58+0.83)(3)=(2.29)(3)=0.76= \frac{(0.88 + 0.58 + 0.83)}{(3)} = \frac{(2.29)}{(3)} = 0.76

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.

RELATED TAGS

CONTRIBUTOR

Arslan Tariq
Copyright Β©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring