# SVM for unbalanced data

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

Thanks!

-

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.

-
Beat me to it :-) –  Marc Claesen Apr 18 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.

-

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.

-
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 yesterday
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 22 hours ago
Yes, why SVM works on sparse data would be nice as well. Thanks –  Tarantula 9 hours ago