hezar.metrics.f1 module

class hezar.metrics.f1.F1(config: F1Config, **kwargs)[source]

Bases: Metric

F1 metric for evaluating classification performance using sklearn’s f1_score.

Parameters:
  • config (F1Config) – Metric configuration object.

  • **kwargs – Extra configuration parameters passed as kwargs to update the config.

compute(predictions: list[int], targets: list[int], labels: list[int] | None = None, pos_label: int | None = None, average: str | None = None, sample_weight: Iterable[float] | None = None, zero_division: str | float = 'warn', n_decimals: int | None = None, output_keys: tuple | None = None, **kwargs)[source]

Computes the F1 score for the given predictions against targets.

Parameters:
  • predictions – Predicted labels.

  • targets – Ground truth labels.

  • labels – List of labels to include in the calculation.

  • pos_label (int) – Label of the positive class.

  • average (str) – Type of averaging for the F1 score.

  • sample_weight (Iterable[float]) – Sample weights for the F1 score.

  • zero_division (str) – Strategy to use for zero-division, default is “warn”.

  • n_decimals (int) – Number of decimals for the final score.

  • output_keys (tuple) – Filter the output keys.

Returns:

A dictionary of the metric results, with keys specified by output_keys.

Return type:

dict

required_backends: list[str | Backends] = [Backends.SCIKIT]
class hezar.metrics.f1.F1Config(objective: str = 'maximize', output_keys: tuple = ('f1',), n_decimals: int = 4, pos_label: int = 1, average: str = 'macro', sample_weight: Iterable[float] | None = None)[source]

Bases: MetricConfig

Configuration class for F1 metric.

Parameters:
  • name (MetricType) – The type of metric, F1 in this case.

  • pos_label (int) – Label of the positive class.

  • average (str) – Type of averaging for the F1 score.

  • sample_weight (Iterable[float]) – Sample weights for the F1 score.

  • output_keys (tuple) – Keys to filter the metric results for output.

average: str = 'macro'
name: str = 'f1'
objective: str = 'maximize'
output_keys: tuple = ('f1',)
pos_label: int = 1
sample_weight: Iterable[float] | None = None