# When there are many more failures than successes should I let classes be equal in SVM? [duplicate]

I have about 5544 runs where I am trying to classify it as failure or success. Here the number of runs that lead to failure is only 64 and rest is sucess. In that case when I try to use SVM should I make the number of classes equal? Will this affect the results?

• Yes. Such data is called unbalanced/imbalanced data. Usually making the number of points per class equal helps a great deal in getting a better classifier. But then, not necessarily the best classifier. You need to try several things here, 1] Try uniformly randomly choosing 64 points from success class and training your SVM 2] Compute the mean of the failure class and choose 64 points from success class which are closest to the failure mean 3] If you are using libSVM, use the entire dataset and provide class weights proportional to the imbalance that you observe – TenaliRaman Nov 18 '12 at 17:33
• @TenaliRaman Thanks for the same.I am using libSVM.Can you please tell me or redirect me to some URL where I can learn about how to provide class weights propotional to imbalance. – Sree Aurovindh Nov 18 '12 at 22:04
• If you check the options of libSVM you will see the -wi option. In your case, (5544 - 64)/64 = 85.625. So, if your label for failure is 0 and success is 1, then you can add the option -w0 85.625 to your libSVM command. – TenaliRaman Nov 19 '12 at 3:36

## 2 Answers

Yes, for a detailed explanation refer to the paper "A geometric interpretation of $\nu$-SVM Classifiers" by David J. Crisp and Christopher J.C. Burges. The idea is that $\nu$ is bounded by the amount $\nu \leq 2l_{min}/l$, where $l_{min}$ is the amount of sample points of the smallest set, and $l$ is the total amount of points.

In an unbalanced problem this amount is very small. At the same time $\nu$ is an upper bound on the fraction of margin errors and a lower bound on the fraction of support vectors. So actually you might end up with a big number of SVs, because the fraction of margin errors is forced to the too low.

See "A User's Guide to Support Vector Machines" by Asa Ben-Hur and Jason Weston for a method to deal with this problem.

Thanks to @TenaliRaman for his answer.I am copying the same.

Yes. Such data is called unbalanced/imbalanced data. Usually making the number of points per class equal helps a great deal in getting a better classifier. But then, not necessarily the best classifier. You need to try several things here, 1] Try uniformly randomly choosing 64 points from success class and training your SVM 2] Compute the mean of the failure class and choose 64 points from success class which are closest to the failure mean 3] If you are using libSVM, use the entire dataset and provide class weights proportional to the imbalance that you observe

If you check the options of libSVM you will see the -wi option. In your case, (5544 - 64)/64 = 85.625. So, if your label for failure is 0 and success is 1, then you can add the option -w0 85.625 to your libSVM command