lazyslide.metrics.segmentation.f1_score

Contents

lazyslide.metrics.segmentation.f1_score#

f1_score(stats)#

Compute F1 score from segmentation statistics.

The F1 score is the harmonic mean of precision and recall, providing a single metric that balances both precision and recall. It reaches its best value at 1 (perfect precision and recall) and worst at 0.

Parameters:
statsSegmentationStats

Segmentation statistics containing true positives (tp), false positives (fp), and false negatives (fn) used to compute precision and recall.

Returns:
float

F1 score in the range [0, 1], where 1 indicates perfect F1 score. A small epsilon (1e-8) is added to the denominator to avoid division by zero.

Notes

F1 = 2 * (precision * recall) / (precision + recall) F1 = 2 * TP / (2 * TP + FP + FN)