如何在clf.predict_proba()中找到相应的类 [英] How to find the corresponding class in clf.predict_proba()
问题描述
我有许多类和相应的特征向量,当我运行Forecast_proba()时,我会得到这个:
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]])
我想得到对应于什么班级的概率.在此页面上说,它们是按照算术顺序排序的,我不确定100%表示什么意思:解决方案
只需使用分类器的.classes_
属性即可恢复映射.在您的示例中,给出了:
>>> clf.classes_
array(['one', 'three', 'two'],
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屋!