Search code examples
matlabclassificationlibsvm

Specify weights in LibSVM in Matlab


I am working on LibSVM on Matlab to solve a classification problem, the data set consist of 32 different classes. The number of instances for some classes is very low. Now I want to set the weights for every class while training a model using OvR approach, can some one help me?


Solution

  • You can use -w parameter to specify weights for unbalanced data. From the documentation:

    -wi weight: set the parameter C of class i to weight*C, for C-SVC (default 1)

    So the parameters you should pass would look something like the below. Classes with smaller number of instances should receive a higher weight:

    -w0 10 -w1 20 -w2 30