如何在 clf.predict_proba() 中找到对应的类 [英] How to find the corresponding class in clf.predict_proba()

查看:34
本文介绍了如何在 clf.predict_proba() 中找到对应的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有许多类和相应的特征向量,当我运行 predict_proba() 时,我会得到这个:

classes = ['one','two','three','one','three']特征 = [[0,1,1,0],[0,1,0,1],[1,1,0,0],[0,0,0,0],[0,1,1,1]]]从 sklearn.naive_bayes 导入 BernoulliNBclf = 伯努利NB()clf.fit(功能,类)clf.predict_proba([0,1,1,0])>>数组([[ 0.48247836, 0.40709111, 0.11043053]])

我想得到什么概率对应什么类.在这个页面上它说它们是按算术顺序排序的,我不是 100% 确定这意味着什么:http://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html#sklearn.svm.SVC.predict_proba>

这是否意味着我已经通过我的训练示例为类的第一次遇到分配了相应的索引,或者是否有像

这样的命令

clf.getClasses() = ['one','two','three']?

解决方案

只需使用分类器的 .classes_ 属性即可恢复映射.在你的例子中,给出:

<预><代码>>>>clf.classes_数组(['一','三','二'],dtype='|S5')

感谢您在问题中放置了一个简约的复制脚本,只需在 IPython shell 中复制和粘贴即可轻松回答:)

I have a number of classes and corresponding feature vectors, and when I run predict_proba() I will get this:

classes = ['one','two','three','one','three']

feature = [[0,1,1,0],[0,1,0,1],[1,1,0,0],[0,0,0,0],[0,1,1,1]]

from sklearn.naive_bayes import BernoulliNB

clf = BernoulliNB()
clf.fit(feature,classes)
clf.predict_proba([0,1,1,0])
>> array([[ 0.48247836,  0.40709111,  0.11043053]])

I would like to get what probability that corresponds to what class. On this page it says that they are ordered by arithmetical order, i'm not 100% sure of what that means: http://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html#sklearn.svm.SVC.predict_proba

Does it mean that I have go trough my training examples assign the corresponding index to the first encounter of a class, or is there a command like

clf.getClasses() = ['one','two','three']?

解决方案

Just use the .classes_ attribute of the classifier to recover the mapping. In your example that gives:

>>> clf.classes_
array(['one', 'three', 'two'], 
      dtype='|S5')

And thanks for putting a minimalistic reproduction script in your question, it makes answering really easy by just copy and pasting in a IPython shell :)

这篇关于如何在 clf.predict_proba() 中找到对应的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆