我们可以使用svm.SVC.score()来评估SVM模型的准确性。如果预测错误,我想获得预测的类(class)和实际的类(class)。如何在scikit-learn中实现呢?

最佳答案

最简单的方法是遍历您的预测(和正确的分类),并对输出进行任何您想要的操作(在下面的示例中,我将其打印到stdout)。

假设您的数据在输入,标签中,而您训练有素的SVM在clf中,那么您可以

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)

关于python - 我可以在scikit-learn中获得错误预测的列表吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45176469/

10-12 07:32