An Exact Algorithm for F-Measure Maximization

Krzysztof Dembczynski, Willem Waegeman, Weiwei Cheng, Eyke Hüllermeier

Introduction

Maximizing the F-measure is notoriously difficult because it lacks a closed-form solution and typically requires knowledge of an exponentially large joint distribution. In machine learning, the F-measure (the harmonic mean of precision and recall) is the go-to metric for imbalanced datasets where standard accuracy is misleading. However, optimizing a model to maximize the expected F-measure is a significant challenge.

Unlike the Hamming loss—which can be optimized by simply thresholding marginal probabilities at 0.5—the F-measure is "non-decomposable." To find the optimal prediction vector, one technically needs to evaluate the entire joint distribution of all possible label combinations. For $m$ labels, there are $2^m$ combinations, making a brute-force search impossible for even moderately sized problems. Previous "exact" methods were too slow ($O(m^4)$), and faster methods relied on the often-false assumption that labels are independent.

This paper introduces the General F-measure Maximizer (GFM), the first algorithm that is both computationally efficient ($O(m^3)$) and theoretically exact for any label distribution, requiring only a quadratic number of parameters.

The GFM Approach

The authors propose a clever mathematical decomposition to bypass the need for the full joint distribution:

  1. Inner/Outer Maximization: The problem is broken into two steps. First, find the best prediction vector $\mathbf{h}$ for a fixed number of positive labels $k$ (inner maximization). Then, iterate through all possible values of $k$ from $0$ to $m$ to find the global winner (outer maximization).
  2. Parameter Reduction: The core breakthrough is realizing that the expected F-measure can be calculated using only $m^2 + 1$ parameters, rather than $2^m$. These parameters are the probability of all zeros $p(\mathbf{Y}=\mathbf{0})$ and a matrix $P$ where each entry $p_{is}$ represents the probability that label $i$ is active given that the total number of active labels is $s$.
  3. The Algorithm:
    • Define a weight matrix $W$ where $w_{sk} = 1/(s+k)$.
  4. Compute a matrix $F = PW$.
  5. For each column $k$ in $F$, the optimal prediction is simply to pick the $k$ labels with the highest values in that column.
  6. The complexity is dominated by matrix multiplication, making it $O(m^3)$ (or even $O(m^{2.376})$ with advanced algorithms), a significant leap over previous exact methods.

Experimental Setup

The authors evaluated GFM using Probabilistic Classifier Chains (PCC) on four well-known multi-label classification (MLC) benchmarks:

  • SCENE: Image classification (6 labels).
  • YEAST: Protein function prediction (14 labels).
  • ENRON: Email categorization (53 labels).
  • MEDIAMILL: Video annotation (101 labels).

They also utilized synthetic datasets to specifically test how the algorithm handles label independence versus dependence.

Key Insights and Results

Independence is a Trap: Many existing algorithms assume labels are independent to simplify the math. This paper proves that if labels are actually dependent (as they often are in text or image tagging), these algorithms suffer from "worst-case regret," meaning their predictions can be significantly suboptimal. GFM avoids this trap entirely.

Thresholding isn't Enough: For many metrics, finding the right probability threshold is sufficient. The authors demonstrate that for the F-measure, the optimal prediction might not even be consistent with the order of marginal label probabilities.

Performance and scaling of GFM compared to baselines

Efficiency and Accuracy: GFM's theoretical exactness translates directly to better performance and vastly superior scaling in practice. In synthetic tests with dependent labels, GFM significantly outperformed methods that assumed label independence.

When applied to real-world datasets, GFM consistently achieved the highest F-measure scores. More impressively, it demonstrated massive efficiency gains. On the Mediamill dataset ($m=101$), the previous state-of-the-art exact method (MEUF) took over 3.5 days (approx. 308,582 seconds) to run. GFM completed the same task in about 23 minutes (approx. 1,420 seconds).

Results on benchmark datasets showing F-measure and inference time

Limitations and Future Work

  • Estimation Quality: While GFM is theoretically "exact," its real-world performance is bottlenecked by the probability estimates it receives. Estimating $m^2$ parameters accurately requires a sufficient amount of data or a highly accurate generative model.
  • Micro vs. Macro: This paper focuses on instance-wise F-measure (optimizing for each specific example). Optimizing for macro or micro F-measure (averaged over a whole dataset) presents a different, potentially more computationally burdensome challenge.
  • Structured Output: The authors suggest that GFM could be adapted for structured output tasks (like natural language parsing), which remains an open area for future implementation.

Summary updated

BibTeX
@inproceedings{dembczynski2011exact,
  author = {Krzysztof Dembczynski and Willem Waegeman and Weiwei Cheng and Eyke Hüllermeier},
  title = {{An Exact Algorithm for F-Measure Maximization}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2011},
}
Figure