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.
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.
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 |
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 $= \frac{(𝑇𝑃_1 + 𝑇𝑃_2 + … + 𝑇𝑃_𝑛)}{(𝑇𝑃_1+𝑇𝑃_2+ … + 𝑇𝑃_𝑛 + 𝐹𝑃_1 + 𝐹𝑃_2 + … + 𝐹𝑃_𝑛)}$
PrecisionMicroAvg $= \frac{(15 + 10 + 5)}{(15 + 10 + 5 + 11 + 90 + 2)} = \frac{(30)}{(133)} = 0.22$
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 $= \frac{(𝑃𝑟𝑒𝑐_1+𝑃𝑟𝑒𝑐_2+…+𝑃𝑟𝑒𝑐_𝑛)}{n}$
PrecisionMacroAvg $= \frac{(0.57 + 0.1 + 0.71)}{(3)} = \frac{(1.38)}{(3)} = 0.46$
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 $= \frac{(𝑇𝑃_1 + 𝑇𝑃_2 + … + 𝑇𝑃_𝑛)}{(𝑇𝑃_1+𝑇𝑃_2+ … + 𝑇𝑃_𝑛 + 𝐹N_1 + 𝐹N_2 + … + 𝐹N_𝑛)}$
RecallMicroAvg $= \frac{(15 + 10 + 5)}{(15 + 10 + 5 + 2 + 7 + 1)} = \frac{(30)}{(40)} = 0.75$
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 $= \frac{(Recall_1+Recall_2+…+Recall_𝑛)}{n}$
RecallMacroAvg $= \frac{(0.88 + 0.58 + 0.83)}{(3)} = \frac{(2.29)}{(3)} = 0.76$
Here is what we can infer about micro and macro averages:
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 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
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.