使用 sklearn 找出错误率

Jan*_*ora 2 python machine-learning svm scikits scikit-learn

我想在 python 中使用 svm 分类器找出错误率,我采取的方法是:

  1-svm.predict(test_samples).mean()
Run Code Online (Sandbox Code Playgroud)

但是,这种方法不起作用。sklearn 的评分函数也给出了平均准确度......但是,我不能使用它,因为我想完成交叉验证,然后找到错误率。请在 sklearn 中建议一个合适的函数来找出错误率。

Fre*_*Foo 6

假设您在向量中有真实标签y_test

from sklearn.metrics import zero_one_score

y_pred = svm.predict(test_samples)
accuracy = zero_one_score(y_test, y_pred)
error_rate = 1 - accuracy
Run Code Online (Sandbox Code Playgroud)