本文介绍了我可以在scikit-learn中获得错误预测的列表吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们可以使用svm.SVC.score()
来评估SVM模型的准确性.如果预测错误,我想获得预测的班级和实际的班级.如何在scikit-learn
中实现这一目标?
We can use svm.SVC.score()
to evaluate the accuracy of the SVM model. I want to get the predicted class and the actual class in case of wrong predictions. How can I achieve this in scikit-learn
?
推荐答案
最简单的方法是遍历您的预测(以及正确的分类),并对输出进行任何操作(在下面的示例中,我将仅打印该输出)到标准输出).
The simplest approach is just to iterate over your predictions (and correct classifications) and do whatever you want with the output (in the following example I will just print it to stdout).
让我们假设您的数据位于输入,标签中,而您训练有素的SVM位于clf中,那么您就可以这样做
Lets assume that your data is in inputs, labels, and your trained SVM is in clf, then you can just do
predictions = clf.predict(inputs)
for input, prediction, label in zip(inputs, predictions, labels):
if prediction != label:
print(input, 'has been classified as ', prediction, 'and should be ', label)
这篇关于我可以在scikit-learn中获得错误预测的列表吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!