SVM classification with different kernels
7 views (last 30 days)
Show older comments
I am using an SVM (SVM_train, Bioinformatics toolbox) to classify data, and I would like to have my final trained SVM models with different kernel functions. I didn't understand how to specify my own kernel maps: if I would like to use a Cauchy kernel defined as
k=(1/(1+(|u-v|^2/sigma))
where u,v are the vectors of the X data, and sigma is the parameter defined by the user (sigma=2.5). How I have to edit this matlab statement?
svmStruct = svmtrain(X,group,'Kernel_Function', 'rbf','RBF_Sigma', 2.5, 'Method', 'QP');
Thank you!
1 Comment
Jeremy Huard
on 31 Jan 2023
Users using R2014b or newer should use the fitcsvm function for for one-class and binary classification or fitcecoc for multiclass classification instead.
There you can specify a custom kernel function by adding the 'KernelFunction','myfunction' name-value pair, where myfunction is the name of your function containing the kernel function definition.
Answers (4)
caterina
on 28 Dec 2012
2 Comments
Ilya
on 28 Dec 2012
Replace
kval = 1/(1+dot);
with
kval = 1./(1+dot);
./ is for elementwise division. / is for matrix division.
Also, please do not post follow-up questions as answers to your own posts. Use comments for that.
hi
svmStruct = svmtrain(x,group,'Kernel_Function', @(u,v) kfun(u,v,p1), 'Method', 'QP');
how will the function call change if i use fitcsvm instead of svmtrain.
can you please help me.
Sandy
on 3 Oct 2014
Hi Caterina,
Just want to check whether you are able to rectify tha above issues. I am also getting the same error. Will you post me the code for above custom kernel.
Thanks in advance.
0 Comments
muqdad aljuboori
on 2 Apr 2017
Hi I very interested in this discussion I tried to apply the new funcion in my project but it doesnt work that what i did
SVR1 = fitrsvm(TrainInputs,TrainTargets,...
'KernelFunction', @(u,v) kfun3(u,v) ,...
'KernelScale','auto','Standardize',true);__
and the error is
Error using classreg.learning.modelparams.SVMParams.make (line 225) You must pass 'KernelFunction' as a character vector.
Error in classreg.learning.FitTemplate/fillIfNeeded (line 598) this.MakeModelParams(this.Type,this.MakeModelInputArgs{:});
Error in classreg.learning.FitTemplate.make (line 124) temp = fillIfNeeded(temp,type);
any suggestion ??? thanks
1 Comment
Jeremy Huard
on 31 Jan 2023
You should specify the kernel function as char array:
SVR1 = fitrsvm(TrainInputs,TrainTargets,...
'KernelFunction', 'kfun3',...
'KernelScale','auto','Standardize',true);
See Also
Categories
Find more on Classification Ensembles in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!