python - 如何在 clf.predict_proba() 中找到对应的类

标签 python machine-learning scikit-learn

我有许多类和对应的特征向量,当我运行 predict_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% 确定这意味着什么:http://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html#sklearn.svm.SVC.predict_proba

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

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

最佳答案

只需使用分类器的 .classes_ 属性即可恢复映射。在您的示例中:

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

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

关于python - 如何在 clf.predict_proba() 中找到对应的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16858652/

相关文章:

python - 即使学习率很小,当类别数量增加时,“模型因损失= NaN而发散”。 [ tensorflow ]

python - 如何使用 matplotlib 在子图中调整图形大小

python - Sympy - 从三角方程中得到两个解,我原本期望只有一个

python - 如何将自己的数据集提供给keras image_ocr

python - 使用 GridSearchCV 时跳过禁止的参数组合

python - 在不平衡样本场景中为每个类提取相同数量的样本

python - sklearn 的 TfidfVectorizer 词频?

python - "How to Fix:TypeError __init() got an unexpected keyword argument ' max_value' 与进度条相关

python - 动态从列表-字典混合列表中获取值

machine-learning - 为什么不训练部分时期呢?