holisticai.bias.metrics.confusion_matrix#
- holisticai.bias.metrics.confusion_matrix(y_pred, y_true, classes=None, normalize=None)[source]#
Confusion Matrix
This function computes the confusion matrix. The i, jth entry is the number of elements with predicted class i and true class j.
Parameters
- y_predarray-like
Prediction vector (categorical)
- y_truearray-like
Target vector (categorical)
- classeslist, optional
The unique output classes in order
- normalizestr, optional
According to which of pred or class we normalize: None, ‘pred’ or ‘class’
Returns
- numpy ndarray
Confusion Matrix : shape (num_classes, num_classes)
Examples
>>> import numpy as np >>> from holisticai.bias.metrics import confusion_matrix >>> y_pred = np.array([0, 1, 2, 0, 1, 2, 0, 1, 2, 0]) >>> y_true = np.array([0, 1, 1, 0, 1, 0, 2, 1, 2, 1]) >>> confusion_matrix(y_pred, y_true, classes=[2, 1, 0]) 2 1 0 2 1.0 1.0 1.0 1 0.0 3.0 0.0 0 1.0 1.0 2.0