Machine Learning Confusion Matrix

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

              represents the true classification. Ground truth (correct) target values.

y_pred  : array type of length n_samples

               Represents the predicted classification value for n examples by the classifier. Estimated targets as returned by a classifier.

labels  : [optional parameter], an array type of length n_classes ( n_classes represents the number of categories/labels )

               This parameter is in the form of a list of labels, which affects the meaning of the row and column representation of the output confusion matrix C, and which type of value is output first .

                 This matrix may be used to rearrange or select a subset to compute the confusion matrix. 

              If this parameter is not given (i.e. None), then  the value that appears at least once in y_true or  y_predwill be used for the sort order

                 Notes: 1. The columns of the confusion matrix represent the order of the categories 2. The values ​​appearing in  or  represent the class labels . y_truey_pred

               List of labels to index the matrix. This may be used to reorder or select a subset of labels. 

               If none is given, those that appear at least once in y_true or y_pred are used in sorted order.

sample_weight : 类似长度为n_samples的数组形式,可选参数。

                             样例的权重向量。Sample weights.

Returns:

返回值:

C : array, shape = [n_classes, n_classes]


返回混淆矩阵(Confusion matrix)C,shape=(n_classes, n_classes)。

混淆矩阵的性质:

        矩阵的对角线表示正确分类的个数,非对角线的点是分类错误的情况。



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325151573&siteId=291194637