F1ScoreMetric#
- class brainstate.nn.F1ScoreMetric(num_classes=None, average='macro')#
F1 score metric for binary and multi-class classification.
F1 score is the harmonic mean of precision and recall: F1 = 2 * (precision * recall) / (precision + recall)
- Parameters:
- precision_metric#
Internal precision metric.
- Type:
- recall_metric#
Internal recall metric.
- Type:
Examples
>>> import jax.numpy as jnp >>> import brainstate >>> predictions = jnp.array([1, 0, 1, 1, 0]) >>> labels = jnp.array([1, 0, 0, 1, 0]) >>> metric = brainstate.nn.F1ScoreMetric() >>> metric.update(predictions=predictions, labels=labels) >>> metric.compute() Array(0.8, dtype=float32)
Notes
The F1 score balances precision and recall, providing a single metric that considers both false positives and false negatives.