The role of the confusion matrix : an indicator for evaluating the learning effect of machine learning. confusion matrix is to evaluate the accuracy of a classification.
Definition of confusion matrix: For confusion matrix C , C (i,j) indicates that the true classification is theiclass, but the predicted value is thetotal number of observationsj
For a binary classification problem (assuming 1 is the positive class):
C (0,0) represents the true negative class TN (true negative) | C (0,1) represents the false positive class FP (false negative) |
C (1,0) represents the false negative class FP (false negative) | C (1,1) represents the true class TP (true positive) |
Implementation of confusion matrix:
By computing the confusion matrix using the scikit-learn module,
sklearn.metrics.confusion_matrix(y_true, y_pred, labels=None, sample_weight=None).
The parameters are explained below: (Note: the array type in the table corresponds to the list list() type in python)
Parameters: parameter: |
y_true : array type of length n_samples
y_pred : array type of length n_samples
labels : [optional parameter], an array type of length n_classes ( n_classes represents the number of categories/labels )
sample_weight : 类似长度为n_samples的数组形式,可选参数。
|
Returns: 返回值: |
C : array, shape = [n_classes, n_classes] 返回混淆矩阵(Confusion matrix)C,shape=(n_classes, n_classes)。 |
矩阵的对角线表示正确分类的个数,非对角线的点是分类错误的情况。