Take the 2-minute tour ×
Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. It's 100% free, no registration required.

I want to attempt to use Support Vector Machines (SVMs) on my dataset. Before I attempt the problem though, I was warned that SVMs dont perform well on extremely unbalanced data. In my case, I can have as much as 95-98% -1's and 2-5% 1's.

I tried to find resources which talked about using SVMs on sparse/unbalanced data, but all I could find was 'sparseSVMs' (which use a small amount of support vectors).

I was hoping someone could briefly explain:

1) how well SVM would be expected to do with such a dataset
2) which, if any, modifications must be done to the SVM algorithm 3) what resources/papers discuss this


share|improve this question

3 Answers 3

Many SVM implementations address this by assigning different weights to positive and negative instances. Essentially you weigh the samples so that the sum of the weights for the positives will be equal to that of the negatives. Of course, in your evaluation of the SVM you have to remember that if 95% of the data is negative, it is trivial to get 95% accuracy by always predicting negative. So you have to make sure your evaluation metrics are also weighted so that they are balanced.

Specifically in libsvm, which you added as a tag, there is a flag that allows you to set the class weights (-w I believe, but check the docs).

Finally, from personal experience I can tell you that I often find that an SVM will yield very similar results with or without the weight correction.

share|improve this answer
Beat me to it :-) –  Marc Claesen Apr 18 '14 at 20:58

SVMs work fine on sparse and unbalanced data. Class-weighted SVM is designed to deal with unbalanced data by assigning higher misclassification penalties to training instances of the minority class.

share|improve this answer

In the case of sparse data like that SVM will work well.

As stated by @Bitwise you should not use accuracy to measure the performance of the algorithm.

Instead you should calculate the precision, recall and F-Score of the algorithm.

share|improve this answer
May you please expand on your reasoning? Also, how would you go about measuring the F-score once the classification (on the test set) has completed? Thanks –  Tarantula Nov 25 '14 at 0:44
To measure the FScore on the test set you will need to manually classify it, and then compute recall and precision using the manual data vs the predicted data. What would you like me to expand, why SVM works well with sparse data? –  alexandrekow Nov 25 '14 at 9:15
Yes, why SVM works on sparse data would be nice as well. Thanks –  Tarantula Nov 25 '14 at 21:49
"Simply having sparse features does not present any problem for the SVM. One way to see this is that you could do a random rotation of the co-ordinate axes, which would leave the problem unchanged and give the same solution, but would make the data completely non-sparse (this is in part how random projections work" (stats.stackexchange.com/questions/23470/…) –  alexandrekow Nov 26 '14 at 13:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.