Because confusion-matrix
of scikit-learn
could not get each index.
(Maybe you can?)
For example, when determining whether a cat is a cat, 1 is a cat and 0 is not a cat.
Predict preds
and use labels
as correct data.
Convert to numpy matrix
import numpy as np
preds = [0., 1., 1., ..., 0., 1., 0.] #A suitable list of 0 or 1
labels = [0., 1., 1., ..., 0., 1., 0.] #A suitable list of 0 or 1
preds = np.array(preds)
labels = np.array(labels)
Index the cat
one_ind_p = preds == 1
one_ind_l = labels == 1
zero_ind_p = np.logical_not(one_ind_p) #Inversion of bool
zero_ind_l = np.logical_not(one_ind_l)
# array([False, True, True, ..., False, True, False])It becomes data like
Get the index of each element of the confusion matrix
tp = np.argwhere(one_ind_l & one_ind_p)
fp = np.argwhere(zero_ind_l & one_ind_p)
fn = np.argwhere(one_ind_l & zero_ind_p)
tn = np.argwhere(zero_ind_l & zero_ind_p)
appendix This is the confusion matrix http://ibisforest.org/index.php?F%E5%80%A4
Recommended Posts