Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out error rate using sklearn

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.

like image 367
Jannat Arora Avatar asked Feb 17 '26 01:02

Jannat Arora


2 Answers

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
like image 106
Fred Foo Avatar answered Feb 19 '26 15:02

Fred Foo


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

like image 35
ogrisel Avatar answered Feb 19 '26 14:02

ogrisel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!