class
ConfusionMatrix
PythonAccumulate class counts and return a row-normalized confusion matrix.
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. |
attribute
num_classes
Pythonnum_classes = int(num_classes)attribute
conf_matrix
Pythonconf_matrix = self.add_variable(name='conf_matrix', shape=(self.num_classes, self.num_classes), initializer='zeros', dtype=self._state_dtype)method
update_state
PythonAdd a batch of labels and predictions to the accumulated counts.
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
| Type | Description |
|---|---|
ValueError | A true or predicted label is outside the class range in eager execution. TensorFlow graph execution uses an assertion. |
method
result
PythonReturns the row-normalized confusion matrix as float64.
result()Returns the row-normalized confusion matrix as float64.
method
reset_state
Pythonreset_state()method
get_config
Pythonget_config()