fitcecoc with specified Box Contraint and Kernel Scale
Show older comments
Hello,
I want to create an SVM model for multiclass classification, with specified hyperparameters: BoxContraint = 500 and KernelScale = 0.01
I triend using:
cvpt = cvpartition(Y_train, "kFold", 5);
fitcecoc(X_train,"class", "CVPartition",cvpt, "Coding","onevsone", "BoxContraint", 500, "KernelScale", 0.01)
I get the following error:
Error in classreg.learning.FitTemplate.make (line 124)
temp = fillIfNeeded(temp,type);
Error in classreg.learning.FitTemplate/fillIfNeeded (line 448)
classreg.learning.FitTemplate.make(this.Method,'type',this.Type,...
Error in classreg.learning.FitTemplate.make (line 124)
temp = fillIfNeeded(temp,type);
Error in ClassificationECOC.template (line 111)
temp = classreg.learning.FitTemplate.make('ECOC','type','classification',varargin{:});
Error in ClassificationECOC.fit (line 115)
temp = ClassificationECOC.template(varargin{:});
Error in fitcecoc (line 339)
obj = ClassificationECOC.fit(X,Y,ecocArgs{:});
Answers (1)
The error occurs because BoxConstraint and KernelScale are NOT name-value pairs of fitcecoc. They are properties of the binary learners (in this case, SVMs) that fitcecoc uses under the hood.
"fitcecoc" itself only orchestrates the ECOC (error-correcting output codes) reduction of a multiclass problem to a collection of binary (two-class) classification problems. For example, one SVM per binary problem in the default one-vs-one scheme.
So, BoxConstraint and KernelScale have to be set in the SVM learner via templateSVM, and that templateSVM is then handed to fitcecoc through the "Learners" name-value argument. Here is an example:
% The templateSVM captures every SVM-specific setting (kernel function, box
% constraint, kernel scale, standardization, etc.). fitcecoc then clones
% this template for each binary sub-problem.
t = templateSVM( ...
KernelFunction = "linear", ...
BoxConstraint = 0.5, ...
KernelScale = "auto", ...
Standardize = false);
mdl = fitcecoc(X, Y, Learners = t, ClassNames = unique(Y));
See the documentation page https://www.mathworks.com/help/stats/fitcecoc.html for more information. Note that fitcecoc also supports other types of binary learners.
Categories
Find more on Image Category Classification 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!