Machine LearningMetrics and Evaluation

F1 vs F-beta

Question 288 of 303 · Updated

On this page

F1 is one specific F-score that values precision and recall equally. F-beta is the general family that lets you deliberately favor recall or precision. F1 is simply F-beta with .

1. Start with precision and recall#

For a binary classifier, define:

  • True positive (TP): a real positive correctly predicted positive.
  • False positive (FP): a negative incorrectly predicted positive.
  • False negative (FN): a positive incorrectly missed.
LaTeX

Precision asks, “When the model raises a positive alert, how often is it right?” Recall asks, “Of all real positive cases, how many did it find?”

Increasing recall often means accepting more positive predictions, which can also increase false positives and reduce precision. The right balance depends on the consequences of each error.

2. F1: equal mathematical emphasis#

F1 is the harmonic mean of precision and recall:

LaTeX

It ranges from 0 to 1. A high score requires both precision and recall to be reasonably high; a very low value for either pulls the harmonic mean down.

Example — fraud detection

Suppose a model produces:

  • TP = 30: fraud cases correctly flagged.
  • FP = 10: legitimate transactions incorrectly flagged.
  • FN = 20: fraud cases missed.

Then:

LaTeX
LaTeX
LaTeX

The model's F1 is 66.7%. F1 is useful when neither false alarms nor missed positives should dominate the evaluation.

3. F-beta: choose the precision–recall emphasis#

F-beta generalizes F1:

LaTeX

An equivalent count-based expression is:

LaTeX

The beta-squared term controls the relative emphasis:

  • : F1; precision and recall have equal emphasis.
  • : recall receives more emphasis. F2 (beta = 2) is a common recall-oriented choice.
  • : precision receives more emphasis. F0.5 (beta = 0.5) is a common precision-oriented choice.

Beta is not a direct business-cost ratio. It is a parameter in a metric. Select it based on the task's priorities, then validate the resulting model against operational costs and constraints.

Same predictions, different beta#

Using the fraud example above (precision = 0.75 and recall = 0.60):

LaTeX
LaTeX
LaTeX

The predictions did not change. Only the evaluation preference changed:

  • F2 is lower because it puts more emphasis on the weaker recall value.
  • F0.5 is higher because it puts more emphasis on the stronger precision value.

These scores are not evidence that the model itself improved or deteriorated. They answer different evaluation questions.

4. When should you use each?#

Choose F1 when:

  • False positives and false negatives both matter.
  • You have no justified reason to favor one over the other.
  • You want a familiar precision–recall summary for a positive class.

Choose F-beta when:

  • Missing a real case is especially costly: consider beta greater than 1. Examples include screening, safety alerts, or finding relevant documents where omissions are costly.
  • False alarms are especially costly: consider beta below 1. Examples include expensive manual investigations or high-precision search results.
  • You can explain and defend the chosen trade-off to product, risk, and operations stakeholders.

Do not choose beta simply because one score looks better. Choose it before comparing candidate models, document the reason, and keep it consistent across experiments.

5. Class imbalance: useful, but not a complete solution#

Accuracy can be misleading when a positive class is rare. For example, if only 10 of 1,000 transactions are fraudulent, a classifier that predicts every transaction as legitimate achieves 99% accuracy but has zero fraud recall. Its positive-class F1 and F-beta are also zero under the usual zero-division convention.

F1 and F-beta focus on precision and recall for the selected positive class, so they can reveal failures hidden by accuracy. But they do not automatically solve class imbalance:

  • They do not include true negatives directly.
  • They do not show how well the negative class is recognized.
  • A score for a rare class can be unstable when the test set contains very few positive examples.
  • In multiclass problems, the averaging method changes how each class contributes.

Always report class support, the confusion matrix, per-class precision and recall, and the metric that matches the business objective. For rare events, evaluate on a representative test set with realistic prevalence; do not rebalance the final test set merely to inflate a score.

6. Macro, micro, and weighted F-scores#

For multiclass or multilabel tasks, calculate a score per class (one-vs-rest) and decide how to combine them. The same averaging choices apply to F1 and F-beta:

  • Macro: calculate the score independently for each class, then average the class scores equally. A rare class has the same class-level weight as a common class.
  • Weighted: average class scores using each class's support (number of actual examples). Common classes contribute more, so weak minority-class performance can be obscured.
  • Micro: pool TP, FP, and FN across classes first, then calculate one score. Frequent classes and decisions contribute more through their counts.
  • None: return one score per class so you can inspect every label.

For ordinary single-label multiclass classification, micro precision, micro recall, micro F1, and micro F-beta coincide with accuracy. That makes micro averaging less informative when the goal is to expose minority-class failures. For multilabel classification, micro aggregation pools label decisions across all samples; sample averaging is a separate approach that scores each example's label set.

A practical report often includes macro F1 or macro F-beta, weighted F1/F-beta, per-class scores, and support. Choose the headline metric based on the actual objective rather than reporting every average without interpretation.

7. Python example with scikit-learn#

Use f1_score for the equal-emphasis case and fbeta_score when you choose another beta:

PYTHON
from sklearn.metrics import ( precision_score, recall_score, f1_score, fbeta_score, classification_report, ) # TP=30, FP=10, FN=20, TN=40 y_true = [1] * 30 + [0] * 10 + [1] * 20 + [0] * 40 y_pred = [1] * 30 + [1] * 10 + [0] * 20 + [0] * 40 p = precision_score(y_true, y_pred, zero_division=0) r = recall_score(y_true, y_pred, zero_division=0) print("Precision:", p) # 0.75 print("Recall:", r) # 0.60 print("F1:", f1_score(y_true, y_pred)) # 0.6667 print("F2:", fbeta_score(y_true, y_pred, beta=2)) # 0.625 print("F0.5:", fbeta_score(y_true, y_pred, beta=0.5)) # 0.7143 # For a multiclass problem: # classification_report(y_true, y_pred, zero_division=0)

For multiclass or multilabel data, choose average="macro", "micro", "weighted", or None explicitly. For example:

PYTHON
from sklearn.metrics import fbeta_score macro_f2 = fbeta_score( y_true, y_pred, beta=2, average="macro", zero_division=0 ) weighted_f05 = fbeta_score( y_true, y_pred, beta=0.5, average="weighted", zero_division=0 )

The example's y_true and y_pred are binary, so use a multiclass dataset before interpreting macro or weighted results in a real project. The zero_division setting makes undefined class-level cases explicit; choose a policy appropriate to the evaluation and report it.

8. Threshold selection matters#

F1 and F-beta are calculated from predicted labels, not directly from probability estimates. A classifier's decision threshold determines which examples become positive. Lowering the threshold often increases recall while reducing precision; raising it often increases precision while reducing recall.

A sound workflow is:

  1. Generate out-of-fold or validation-set probabilities.
  2. Evaluate precision, recall, and the chosen F-beta over candidate thresholds.
  3. Choose the threshold using validation data and predeclared operational constraints.
  4. Freeze the threshold and evaluate once on an untouched test set.
  5. Monitor the same metric, threshold, class prevalence, and per-class error rates in production.

Do not tune beta or the threshold on the final test set. If missing a positive must remain below a fixed limit, enforce a recall constraint directly rather than assuming a single F-beta score guarantees it.

9. Limitations and common mistakes#

  • Neither metric includes true negatives directly. Add specificity, confusion-matrix analysis, or another measure if correct negative predictions matter.
  • Neither represents monetary or safety cost by itself. If FP and FN have known costs, calculate expected cost or utility alongside F-beta.
  • F-beta is not a probability or a calibrated confidence score. It summarizes hard classification outcomes.
  • A higher F-beta does not guarantee a better operational model. Check workload, latency, subgroup behavior, and error severity.
  • Do not confuse beta with the averaging method. Beta sets precision–recall emphasis; macro, micro, and weighted specify how class scores are combined.
  • Handle undefined cases consistently. If no positive examples are predicted or present for a class, precision, recall, or the F-score may be undefined. Set and document the library's zero-division behavior.
  • Avoid leakage. Choose beta, thresholds, and model settings using training/validation data, not the final test set.

10. Production selection checklist#

  • Define which error is more harmful: false positives or false negatives.
  • If the two are comparably important, start with F1. If missed positives are more costly, evaluate F2 or another beta above 1. If false alarms are more costly, evaluate F0.5 or another beta below 1.
  • Select the positive class explicitly and inspect per-class metrics.
  • For imbalanced multiclass tasks, compare macro and weighted results and retain per-class support.
  • Tune thresholds on representative validation data and verify operational constraints separately.
  • Evaluate on a realistic untouched test set; monitor prevalence and metric drift after deployment.
  • Keep business cost, calibration, precision, recall, and workload visible rather than reducing the release decision to one score.

Interview answer: F1 is the harmonic mean of precision and recall with equal emphasis. F-beta generalizes it: beta greater than 1 emphasizes recall, beta below 1 emphasizes precision, and beta equal to 1 is exactly F1. Use F1 for a balanced precision–recall objective and F-beta when the application justifies a deliberate preference for one type of error.

Related questions

Explore other topics:Deep LearningMLOps