Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

How to customize SVM kernel parameters in Matlab

Asked by Ikra89 on 9 Jun 2013

Hi

I want to ask about how to customize SVM kernel parameters in Matlab.

For ex: I have linear kernel, polynomial kernel, and RBF kernel with:

C = 0.2;
gamma = 0.8;
r = 0.05;
d = 3;

My question is how do I customize it using svmstruct.

1. linear: ??

2. polynomial: ??

3. RBF:

svmstruct = svmtrain(data, groups, 'Kernel_Function', 'rbf', 'RBF_Sigma', 0.2, 'BoxConstraint', 0.8);

CMIIW about how to customize RBF kernel.

I'd really appreciate if anybody could help my research. Thanks.

Regards

Ikra

0 Comments

Ikra89

Products

2 Answers

Answer by Ikra89 on 10 Jun 2013

anybody can help? :)

0 Comments

Ikra89
Answer by Ahmed on 10 Jun 2013

Documentation given by

   help svmtrain

should give you all information you need. What is the meaning of your variable r?

1. the linear kernel has only parameter C

   svmstruct = svmtrain(data, groups, 'Kernel_Function', 'linear', 'BoxConstraint', 0.2);

2. polynomial has parameters C and polyorder

   svmstruct = svmtrain(data, groups, 'Kernel_Function', 'polynomial', 'polyorder',3,'BoxConstraint', 0.2);

3. RBF

you might have mixed up the constants C and gamma in your code

4 Comments

Ahmed on 10 Jun 2013

It looks like Matlab's svmtrain function only supports homogeneous polynomial kernels. You can however, define an arbitrary kernel function and pass a handle of it to svmtrain. See section kernel_function -> @kfun in the documentation for description and example.

Ikra89 on 12 Jun 2013

can you give me an example how to use @kfun

i have tried many times but still error

Ahmed on 6 Jul 2013

Using an anonymous function of a linear kernel would be:

svmstruct = svmtrain(data, groups, ...
'Kernel_Function',@(x1,x2) x1*x2','BoxConstraint', 0.2);

Note, that your kernel function must lead to a valid kernel.

Ahmed

Contact us