# helia_edge.metrics.confusion_matrix

## Confusion Matrix Metric API

**Classes**

| Name | Description |
| --- | --- |
| `ConfusionMatrix` | Accumulates a confusion matrix and returns row-normalized values. |

## helia_edge.metrics.confusion_matrix.ConfusionMatrix

`class` · `python`

```python
ConfusionMatrix(num_classes: int, name='confusion_matrix', **kwargs={})
```

Accumulate class counts and return a row-normalized confusion matrix.

Rows represent true classes and columns represent predicted classes.
Rows with no observations return zeros. State accumulates across batches
until reset_state() is called.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| num_classes | int | Required | Number of classes, defining both matrix dimensions. |
| name | str | 'confusion_matrix' | Keras metric name. |
| **kwargs | Any | {} | Additional Keras Metric arguments, including state dtype. |

Source: `helia_edge/metrics/confusion_matrix.py:14`

### helia_edge.metrics.confusion_matrix.ConfusionMatrix.num_classes

`attribute` · `python`

```python
num_classes = int(num_classes)
```

Source: `helia_edge/metrics/confusion_matrix.py:30`

### helia_edge.metrics.confusion_matrix.ConfusionMatrix.conf_matrix

`attribute` · `python`

```python
conf_matrix = self.add_variable(name='conf_matrix', shape=(self.num_classes, self.num_classes), initializer='zeros', dtype=self._state_dtype)
```

Source: `helia_edge/metrics/confusion_matrix.py:32`

### helia_edge.metrics.confusion_matrix.ConfusionMatrix.update_state

`method` · `python`

```python
update_state(y_true, y_pred, sample_weight=None)
```

Add a batch of labels and predictions to the accumulated counts.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| y_true | Tensor | Required | Integer class labels, flattened before accumulation. |
| y_pred | Tensor | Required | Class scores with shape (batch, ..., num_classes), reduced with argmax over the last axis, or matching integer labels. |
| sample_weight | Tensor \| None | None | Optional weights, flattened to one value per label. |

**Raises**

| Name | Description |
| --- | --- |
| ValueError | A true or predicted label is outside the class range in eager execution. TensorFlow graph execution uses an assertion. |

Source: `helia_edge/metrics/confusion_matrix.py:39`

### helia_edge.metrics.confusion_matrix.ConfusionMatrix.result

`method` · `python`

```python
result()
```

Returns the row-normalized confusion matrix as float64.

Source: `helia_edge/metrics/confusion_matrix.py:99`

### helia_edge.metrics.confusion_matrix.ConfusionMatrix.reset_state

`method` · `python`

```python
reset_state()
```

Source: `helia_edge/metrics/confusion_matrix.py:106`

### helia_edge.metrics.confusion_matrix.ConfusionMatrix.get_config

`method` · `python`

```python
get_config()
```

Source: `helia_edge/metrics/confusion_matrix.py:110`
