Scikit学习混淆矩阵

时间:2013-08-22 22:44:50

标签: python matplotlib scikit-learn confusion-matrix

我正在用sci-kit制作混淆矩阵,学习两个不同的列表:gold_labels和预测标签

cm = confusion_matrix(gold_labels, predicted_labels)
pl.matshow(cm) #I use pl to generate an image
pl.title('Confusion Matrix')
pl.ylabel('True label')
pl.xlabel('Predicted label')
pl.colorbar()

其中黄金标签/预测标签看起来像这样:(字符串列表)

gold_labels =["hello", "apple".....] 
predicted_labels=["hi", "apple"....]

生成混淆矩阵并且它看起来很漂亮但是标签是索引(0,1,2)并且我无法判断0是否映射到“hello”或“apple” 所以,我有两个问题: 1)是否有办法使标签出现在pl中生成的混淆矩阵中 2)如果没有,我怎么知道我的字符串列表中的内容与其对应的索引匹配

1 个答案:

答案 0 :(得分:1)

只需拨打plt.xticksplt.yticks功能。

首先,您必须选择您希望刻度线在轴上的位置,然后您必须设置标签。

例如:假设您有一个x轴,其范围从525,您希望在815和{{ 1}},您想要标签22foobar

然后你应该打电话:

baz

在您的情况下,由于您的标签标记位于# do your plotting first, for example x = np.arange(5, 25) y = x * x plt.plot(x, y) # and then the ticks plt.xticks([8, 15, 22], ['foo', 'bar', 'baz']) # And finally show the plot plt.show() ,并且您希望[0, 1, 2]helloapple作为标签。你应该这样做:

orange
相关问题