Skip to content

Fmax score (or maximum of F1/Fbeta) #26026

Closed as not planned
Closed as not planned

Description

@jasperhyp

Describe the workflow you want to enable

The maximum of F1 across thresholds is a well-studied metric and it is both robust and valid in binary and multilabel classification problems. Basically, it can be computed with precision_recall_curve, as shown below, for binary problems. For multilabel problems, I'm not sure if there is an efficient way to do this without looping thru all labels.

Describe your proposed solution

For binary:

def get_fmax(preds: np.ndarray, ys: np.ndarray, beta = 1.0, pos_label = 1):
    """
    Radivojac, P. et al. (2013). A Large-Scale Evaluation of Computational Protein Function Prediction. Nature Methods, 10(3), 221-227.
    """
    precision, recall, thresholds = precision_recall_curve(y_true = ys, probas_pred = preds, pos_label = pos_label)
    numerator = (1 + beta**2) * (precision * recall)
    denominator = ((beta**2 * precision) + recall)
    fbeta = np.divide(numerator, denominator, out=np.zeros_like(numerator), where=(denominator!=0))
    
    return np.nanmax(fbeta), thresholds[np.argmax(fbeta)]

Describe alternatives you've considered, if relevant

No response

Additional context

No response

Activity

  1. changed the title [-]`Fmax` score (or maximum of F1)[/-] [+]`Fmax` score (or maximum of F1/Fbeta)[/+] on Mar 30, 2023
  2. ogrisel commented on Apr 6, 2023

    @ogrisel
    Member

    I had never heard of this. Is this used in other papers besides the one linked in the docstring?

  3. added
    Needs Decision - Include Feature
    and removed
    Needs Triage
    on Apr 6, 2023
  4. jasperhyp commented on Apr 6, 2023

    @jasperhyp
    Author

    I had never heard of this. Is this used in other papers besides the one linked in the docstring?

    I believe it's mainly used for highly imbalanced classification (as a supplement to AUPRC and various @k metrics). Specifically, in bioinformatics, imbalanced problems are just so frequent -- especially for function predictions. For example, the CAFA challenge, the major competition in protein function prediction benchmarking, uses Fmax as the key metric for comparison, see https://genomebiology.biomedcentral.com/articles/10.1186/s13059-019-1835-8. There are also various standard tasks and high-profile papers in functional genomics that uses Fmax as a standard metric.

    See some discussions over the idea of finding the optimal threshold for precision-recall curve at:
    https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4442797/
    https://towardsdatascience.com/optimal-threshold-for-imbalanced-classification-5884e870c293
    https://machinelearningmastery.com/threshold-moving-for-imbalanced-classification/
    https://stats.stackexchange.com/questions/182331/what-is-f1-optimal-threshold-how-to-calculate-it

  5. lesteve commented on Nov 3, 2025

    @lesteve
    Member

    Olivier never heard of this, nobody in 2+ years expressed interest, so it's very unlikely that it will be at the top of our priorities in the foreseeable future. I am going to close this one.

    Happy to reopen in case the situation changes significantly somehow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs Decision - Include FeatureNeeds InfoNew Feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions