Find out error rate using sklearn

Jannat Arora picture Jannat Arora · Apr 25, 2012 · Viewed 19.2k times · Source

I want to find out the error rate using svm classifier in python, the approach that I am taking to accomplish the same is:

  1-svm.predict(test_samples).mean()

However, this approach does not work. Also the score function of sklearn gives mean accuracy...however, I can not use it as I want to accomplish cross-validation, and then find the error-rate. Please suggest a suitable function in sklearn to find out the error rate.

Answer

Fred Foo picture Fred Foo · Apr 26, 2012

Assuming you have the true labels in a vector 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