2013-08-22 251 views
0

我正在与SCI-KIT混淆矩阵学会用两种不同的列表:gold_labels和预测标签Scikit学习混淆矩阵

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映射到“你好”或“苹果” 所以,我有我不能告诉两个问题: 1)有没有办法让标签出现在PL 2)如果没有产生混淆矩阵,我怎么知道我的字符串列表如何与其对应的索引

+0

我不太明白你的问题。你能把标签放在混淆矩阵上吗?如果是这样,这里有一个例子,我回答了前一段时间有关如何做到这一点... http://stackoverflow.com/questions/2897826/confusion-matrix-with-number-of-classified-misclassified-instances-on-it -python/2901740#2901740 – tom10

+0

不,我的意思是,而不是数字显示为标签(0,1,2,3)我想字符串(你好,苹果出现) – user1011332

回答

1

匹配只要打电话给plt.xticksplt.yticks功能。

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

例如:假设你有一个x轴跨越从525,你想3个蜱在81522,并且希望标签foobarbaz

那么你应该叫:

# 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],你想helloappleorange为您的标签。你应该这样做:

plt.xticks([0, 1, 2], ['hello', 'apple', 'orange'])