fbeta#
- openstef_beam.metrics.fbeta(precision_recall: PrecisionRecall, beta: float = 2.0) float[source]#
Calculate the F-beta score from precision and recall metrics.
The F-beta score is a weighted harmonic mean of precision and recall, allowing for different emphasis on recall versus precision based on the beta parameter.
- Parameters:
precision_recall (PrecisionRecall) – Container with precision and recall values from the precision_recall function.
beta (float) – Weight parameter controlling the relative importance of recall. Values > 1 favor recall, values < 1 favor precision. Common values: 0.5 (favor precision), 1.0 (balanced F1), 2.0 (favor recall).
- Returns:
The F-beta score as a float in range [0, 1]. Returns 0.0 if both precision and recall are zero.
- Return type:
float
Example
Calculate F2 score (favoring recall):
>>> pr = PrecisionRecall(precision=0.8, recall=0.9) >>> score = fbeta(pr, beta=2.0) >>> round(score, 3) 0.878
Calculate F1 score (balanced):
>>> score = fbeta(pr, beta=1.0) >>> round(score, 3) 0.847
Note
F-beta scores are particularly useful for imbalanced datasets where the cost of false positives and false negatives differs significantly. In energy forecasting, beta > 1 is often preferred to minimize missed peaks.
- Parameters:
precision_recall (
PrecisionRecall)beta (
float)
- Return type:
float