- Introduced by
- Multi-class evaluation community
- Year
- 2000s
- Type
- Evaluation metric
- Family
- Classification Metric
What does it do?
Weighted F1 computes the F1-score for each class and then takes the average of those scores, weighted by each class's support (its number of samples in the evaluation data).
Because the weights come from class frequencies, classes that occur more often contribute more to the final value. The result is a single number that reflects per-class performance without ignoring class frequencies.
The intuition behind the method
Accuracy pools all predictions, so it is dominated by the most frequent class. Macro F1 gives every class the same weight regardless of how often it occurs. Weighted F1 computes F1 separately for each class and then averages those values in proportion to support. A large class therefore moves the score more than a small one, but a small class still contributes its own F1 rather than disappearing from the calculation. Because the weights are class counts, the score is most informative when the class frequencies in the evaluation set match the mix the model will face in use.
History
Weighted F1 is the support-weighted average of per-class F1-scores, a standard construction in multi-class evaluation that belongs to the wider literature on F-measure-based measures. Powers (2011) covers precision, recall and F-measure together with ROC analysis, informedness, markedness and correlation, and Sokolova, Japkowicz and Szpakowicz (2006) present a family of discriminant measures for performance evaluation.
When to use it
Use weighted F1 for single-label multi-class problems where the class frequencies in the evaluation set reflect how often each class occurs in practice, and you still want per-class F1 to shape the score. It suits datasets with moderate imbalance in which the frequent classes should carry more weight but the rarer classes still need to be considered. Do not use it when every class must count equally regardless of frequency; macro F1 is the more appropriate choice then. Also avoid it when the errors have unequal real-world costs, because support weights do not encode cost, and when the evaluation set's class mix differs from the deployment mix, since the score will then describe the wrong population.
Limitations and considerations
- Classes with small support have little influence on the score, so poor F1 on a rare class can be largely hidden.
- The value depends on the support distribution of the evaluation set; scores computed on datasets with different class mixes are not directly comparable.
- A single weighted number summarises the classes unevenly and cannot show which classes drive the result.
- It is less transparent to interpret than a simple per-class table, since the contribution of each class depends on its share of the data.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Uses per-class F1 rather than accuracy, so the balance of precision and recall within each class enters the score.
- Weights each class by its support, so the score reflects how the model performs on the classes that make up most of the evaluation data.
- Produces one number computed directly from the weighted-average formula, which makes it easy to report next to per-class results.
- Because it is a weighted average of per-class F1 values, it cannot fall outside the range spanned by those values.
Applications
- Multi-class text classification problems with natural but uneven class frequencies, such as sentiment or topic labelling.
- Evaluation settings where the class frequencies in the test data are meant to represent their real-world importance.
- Reporting a single summary score alongside per-class F1 values for multi-class benchmarks.
- Comparing candidate models when the choice between macro and micro averaging has not been settled.
How it works
How it works
For each class i, compute the F1-score as the harmonic mean of precision and recall: F1_i = 2 * P_i * R_i / (P_i + R_i), where P_i = TP_i / (TP_i + FP_i) and R_i = TP_i / (TP_i + FN_i). Here TP_i, FP_i and FN_i are the true positives, false positives and false negatives for class i in the evaluation set. Count the support of each class, meaning the number of evaluation samples whose true label is that class. Precision for a class is undefined when the model predicts no samples of that class, and recall is undefined when the class has no true samples in the evaluation set. Report the convention the implementation uses for these cases, for example excluding the class or assigning it an explicit value, because the choice changes the weighted average.
Compute the weighted average of the per-class F1-scores, with each class weighted by its support: weighted F1 = sum(support_i × F1_i) / sum(support_i). The denominator is the total number of evaluation samples.
Each per-class F1 lies between 0 and 1, so the weighted average does too. Since it is a weighted average, the result always lies between the lowest and highest per-class F1 values. Where it falls in that range depends on the support distribution: when a few large classes dominate the sample, the value moves toward their F1 scores, and small classes have little effect on it.
Common pitfalls
- Reporting only the weighted F1 without the per-class F1 values, so that failures on minority classes remain hidden.
- Confusing support weights with misclassification costs; the weights are class counts and say nothing about how costly each error type is.
- Assuming weighted F1 corrects class imbalance. It does not change the model or the data; it only reflects the existing class frequencies in the score.
- Computing support from the training distribution rather than the evaluation set, which changes the weights and therefore the value.
- Applying weighted F1 to multi-label data without checking the averaging convention. The definition here covers single-label multi-class problems; for multi-label data, per-label F1 averaged with label-support weights can have a different meaning from micro averaging, so the implementation's convention should be checked and stated in any report.
Frequently asked questions
How does weighted F1 differ from macro and micro F1?
Macro F1 averages per-class F1 with equal weights, so each class counts the same. Micro F1 pools all true positives, false positives and false negatives across classes; for single-label multi-class problems it equals accuracy. Weighted F1 averages per-class F1 with weights equal to class support. Its value always lies between the lowest and highest per-class F1, but it is not guaranteed to lie between the macro and micro values, so the three scores should be reported together rather than read as a fixed ordering.
When should I use weighted F1 instead of accuracy?
Accuracy is the share of all predictions that are correct and does not separate performance across classes. Weighted F1 averages per-class F1, which depends on each class's precision and recall, and then weights those values by class support. It is therefore more informative when the classes differ in how well they are predicted, but it still gives the frequent classes more influence.
Is weighted F1 always better than macro F1?
No. Weighted F1 suits problems where class frequencies reflect importance and where it is acceptable for minority classes to have less influence on the score. Macro F1 suits problems where every class must count equally regardless of frequency. The choice should follow the problem's requirements rather than any general ranking of the two metrics.
Related methods
Sources
Powers, D. M. (2011). Evaluation: From Precision, Recall and F-Measure to ROC, Informedness, Markedness and Correlation. Journal of Machine Learning Technologies, 2(1), 37-63.
Open publication referenceSokolova, M., Japkowicz, N., & Szpakowicz, S. (2006). Beyond Accuracy, F-Score and ROC: a Family of Discriminant Measures for Performance Evaluation. AI 2006, 4013, 1015-1021.
Open DOI reference