问题描述
我有许多类和相应的特征向量,当我运行 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_
属性即可恢复映射.在你的例子中,给出:
感谢您在问题中放置了一个简约的复制脚本,只需在 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() 中找到对应的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!