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=None, targets=None, labels=None, pos_label=1, average=None, sample_weight=None, zero_division='warn', n_decimals=None, output_keys=None)[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