LIBSVM: MATLAB function "trainsvm" deprecated and replaced by "fitcsvm"

41 views (last 30 days)
As MATLAB ha depreciated "svmtrain" and replaced it by "fitcsvm", LIBSVM is giving error:
% This is an example of using precomputed kernel
% using Libsvm in MATLAB, where K is the precomputed kernel (Gram matrix).
model = fitcsvm(TrainLabels, K, '-t 4');
Error using internal.stats.parseArgs (line 42)
Wrong number of arguments.
Error in classreg.learning.paramoptim.parseOptimizationArgs (line 5)
[OptimizeHyperparameters,~,~,RemainingArgs] = internal.stats.parseArgs(...
Error in fitcsvm (line 312)
[IsOptimizing, RemainingArgs] =
Error in myKernelLIBSVM (line 153)
model = fitcsvm(TrainLabels, K, '-t 4');
Earlier, this would work fine using svmtrain.
Error using svmtrain (line 230)
svmtrain has been removed. Use fitcsvm instead.

Accepted Answer

Walter Roberson
Walter Roberson on 22 Jul 2018
You have
fitcsvm(TrainLabels, K, '-t 4')
The valid syntaxes for fitcsvm are
Mdl = fitcsvm(Tbl,ResponseVarName)
Mdl = fitcsvm(Tbl,formula)
Mdl = fitcsvm(Tbl,Y)
Mdl = fitcsvm(X,Y)
Mdl = fitcsvm(___,Name,Value)
The only one of this that permits a third parameter is the last one, with name/value pairs. But '-t 4' is not a name/value pair.
MATLAB's svmtrain() also never supported that syntax. That syntax was valid only for libsvm . You can still pull in libsvm if you want to.
The syntax for fitcsvm never has the label information as a separate first parameter, only integrated as part of the first parameter, or as a second parameter.
You should be having a look at the KernelFunction option

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!