机器学习之混淆矩阵

混淆矩阵的作用对机器学习的学习效果进行评估的一种指标。confusion matrix is to evaluate the accuracy of a classification.它的作用是评估分类的准确度。

混淆矩阵的定义:对于混淆矩阵C,C(i,j) 表示真实分类是第i类,但是预测值为第j类的观测总数。

对于二分类问题(假设1是正类):

C(0,0)表示真反类  TN(true negative) C(0,1)表示假正类  FP(false negative)
C(1,0)表示假反类  FP(false negative) C(1,1)表示真正类  TP(true positive)

混淆矩阵的实现:

    通过使用scikit-learn模块计算混淆矩阵,

  sklearn.metrics.confusion_matrix(y_true, y_pred, labels=None, sample_weight=None).

    下面对参数进行说明:(注:表格中的数组类型在python中对应为列表list()类型)  



Parameters:

参数:

y_true : 长度为n_samples的数组类型

              表示真实分类。Ground truth (correct) target values.

扫描二维码关注公众号,回复: 100332 查看本文章

y_pred : 长度为n_samples的数组类型

               表示由分类器对n个样例的预测分类值。Estimated targets as returned by a classifier.

labels :   [可选参数],长度为n_classes的数组类型 (n_classes表示类别/标签个数)

               这个参数是标签的列表形式,影响输出的混淆矩阵C的行列表示的含义,先输出哪一类的值

                 该矩阵可能被用于重排或者选择其中一个子集计算混淆矩阵。 

              如果不给这个参数(即为None),那么 y_true or y_pred中至少出现一次的值将被用于排列顺序

                 注:1. 混淆矩阵的列表示类别的顺序   2. y_true or y_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)。

混淆矩阵的性质:

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



猜你喜欢

转载自blog.csdn.net/AchangeC/article/details/80104279