3

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.

ogrisel
  • 39,309
  • 12
  • 116
  • 125
Jannat Arora
  • 2,759
  • 8
  • 44
  • 70
  • 2
    Doesn't svm.predict give you an output of classifications? Why would taking the mean do anything useful? – dfb Apr 25 '12 at 15:42

3 Answers3

6

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
Fred Foo
  • 355,277
  • 75
  • 744
  • 836
3

If you want to cross validate a score, use the sklearn.cross_validation.cross_val_score utility function and pass it the scoring function you like from the sklearn.metrics module:

http://scikit-learn.org/dev/modules/cross_validation.html

ogrisel
  • 39,309
  • 12
  • 116
  • 125
1

Use sklearn.metrics.accuracy_score Doc here.

from sklearn.metrics import accuracy_score
#create vectors for actual labels and predicted labels...
my_accuracy = accuracy_score(actual_labels, predicted_labels, normalize=False) / float(actual_labels.size)
tony_tiger
  • 789
  • 1
  • 11
  • 25