ConfusionMatrix¶
Confusion Matrix for binary and multi-class classification.
Parameters¶
-
classes – defaults to
None
The initial set of classes. This is optional and serves only for displaying purposes.
Attributes¶
-
classes
-
total_false_negatives
-
total_false_positives
-
total_true_negatives
-
total_true_positives
Examples¶
>>> from river import metrics
>>> y_true = ['cat', 'ant', 'cat', 'cat', 'ant', 'bird']
>>> y_pred = ['ant', 'ant', 'cat', 'cat', 'ant', 'cat']
>>> cm = metrics.ConfusionMatrix()
>>> for yt, yp in zip(y_true, y_pred):
... cm = cm.update(yt, yp)
>>> cm
ant bird cat
ant 2 0 0
bird 0 0 1
cat 1 0 2
>>> cm['bird']['cat']
1.0
Methods¶
false_negatives
false_positives
revert
support
true_negatives
true_positives
update
Notes¶
This confusion matrix is a 2D matrix of shape (n_classes, n_classes)
, corresponding
to a single-target (binary and multi-class) classification task.
Each row represents true
(actual) class-labels, while each column corresponds
to the predicted
class-labels. For example, an entry in position [1, 2]
means
that the true class-label is 1, and the predicted class-label is 2 (incorrect prediction).
This structure is used to keep updated statistics about a single-output classifier's performance and to compute multiple evaluation metrics.