Metrics API¶
Metrics are stateful epoch accumulators. `Trainer` calls `reset`, feeds each model output and batch to `update`, then calls `compute` to obtain scalar log values. Configure metric factories through the `METRICS` registry. See Metrics for configuration examples.
Contract¶
chimera_ml.metrics.base.BaseMetric ¶
Bases: ABC
Stateful metric extension contract.
Trainer resets a metric at the start of an epoch, calls update for each labeled batch, and merges the mapping returned by compute into logs. Implementations should keep only epoch-local state.
update
abstractmethod
¶
update(output, batch)
Accumulate predictions and targets from one batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
ModelOutput
|
Model predictions for the batch. |
required |
batch
|
Batch
|
Inputs and labeled targets for the batch. |
required |
Regression metrics¶
Regression metrics flatten outputs to `(N, D)` and support uniform or raw multi-output aggregation. R² additionally supports variance-weighted output.
chimera_ml.metrics.regression_metric.RegressionBaseMetric
dataclass
¶
Bases: BaseMetric
Base class for regression metrics.
Accumulates y_true and y_pred during epoch, then computes metric at epoch end. Flattens tensors to (N, D) where D is output dimension.
chimera_ml.metrics.regression_metric.MAEMetric
dataclass
¶
chimera_ml.metrics.regression_metric.MSEMetric
dataclass
¶
chimera_ml.metrics.regression_metric.RMSEMetric
dataclass
¶
chimera_ml.metrics.regression_metric.R2Metric
dataclass
¶
Classification metrics¶
`PRFMetric` reports precision, recall, and F1 with micro, macro, or weighted averaging. `ConfusionMatrixMetric` stores the class matrix and exposes its accuracy summary through `compute` and the matrix through `value`.
chimera_ml.metrics.prf_metric.PRFMetric
dataclass
¶
Bases: BaseMetric
Compute precision, recall, and F1 from accumulated class predictions.
Attributes:
| Name | Type | Description |
|---|---|---|
average |
Literal['micro', 'macro', 'weighted']
|
micro, macro, or weighted aggregation. |
zero_division |
int
|
Value used when a class has no positive denominator. |
The compute method returns keys prefixed with the selected average, for example macro_precision, macro_recall, and macro_f1.
chimera_ml.metrics.confusion_matrix_metric.ConfusionMatrixMetric
dataclass
¶
Bases: BaseMetric
Accumulate class predictions and expose a confusion matrix.
Attributes:
| Name | Type | Description |
|---|---|---|
normalize |
str | None
|
None for counts, or true, pred, or all for normalized matrix values. |
value |
ndarray | None
|
Latest matrix after compute; None before any data is computed. |
The compute method returns a cm_acc scalar; use value to retrieve the matrix.
chimera_ml.metrics.confusion_matrix_metric.confusion_matrix_metric ¶
confusion_matrix_metric(**params)