Help req. in using fitcsvm()

1 Ansicht (letzte 30 Tage)
UserJ
UserJ am 9 Mai 2018
Kommentiert: UserJ am 12 Mai 2018
Hi!
I am trying to use fitcsvm() to implement SVM. Previously, I was using LibSVM. I know from the results obtained using LibSVM that the best kernel for my problem is RBF. Now, I want to find the kernel parameters. For this, I am using the following code:
opts=struct('Optimizer','bayesopt','ShowPlots',true, 'Repartition',1);
svmmod=fitcsvm(ftTrn,CLTrn,'KernelFunction','rbf','OutlierFraction',0.05,...
'OptimizeHyperparameters','auto','HyperparameterOptimizationOptions',opts);
% ftTrn: Training data, %CLTrn: corresponding classlabels
1) Is this code right for my purpose?
2) svmmod contains the SVM trained on the entire training data or on a subset (on a fold used for determining the best values for the kernel parameters)?
3) Are there any other parameters I can tweak for improving the classification performance?

Akzeptierte Antwort

Don Mathis
Don Mathis am 11 Mai 2018
Bearbeitet: Don Mathis am 11 Mai 2018
(1) Yes that's right. In that case it will optimize BoxConstraint and KernelScale.
(2) svmmod contains the SVM trained on the entire training data, using the best hyperparameters found. 5-fold crossvalidated misclassification rate was used as the objective function during optimization.
(3) You can optimize more variables. You can find out what hyperparameters are eligible like this:
>> h = hyperparameters('fitcsvm',ftTrn,CLTrn)
>> h.Name
h =
5×1 optimizableVariable array with properties:
Name
Range
Type
Transform
Optimize
ans =
'BoxConstraint'
ans =
'KernelScale'
ans =
'KernelFunction'
ans =
'PolynomialOrder'
ans =
'Standardize'
And then you can optimize additional hyperparameters like this:
svmmod=fitcsvm(ftTrn,CLTrn,'KernelFunction','rbf','OutlierFraction',0.05,...
'OptimizeHyperparameters',{'BoxConstraint','KernelScale','Standardize'},'HyperparameterOptimizationOptions',opts)
Because you're fixing the kernel function, the 'PolynomialOrder' hyperparameter is not relevant. So 'Standardize' ends up being the only additional hyperparameter.
One more note: Since you're now optimizing 3 variables, you might want to run the optimization longer, say 60 evaluations:
opts=struct('Optimizer','bayesopt','ShowPlots',true, 'Repartition',1, 'MaxObjectiveEvaluations',60);
svmmod=fitcsvm(ftTrn,CLTrn,'KernelFunction','rbf','OutlierFraction',0.05,...
'OptimizeHyperparameters',{'BoxConstraint','KernelScale','Standardize'},'HyperparameterOptimizationOptions',opts)
  2 Kommentare
Don Mathis
Don Mathis am 11 Mai 2018
Yet one more note: If you've got some time on your hands, why not let it try other kernel functions, too?
opts=struct('Optimizer','bayesopt','ShowPlots',true, 'Repartition',1, 'MaxObjectiveEvaluations',60);
svmmod=fitcsvm(ftTrn,CLTrn,'OutlierFraction',0.05,...
'OptimizeHyperparameters','all','HyperparameterOptimizationOptions',opts)
UserJ
UserJ am 12 Mai 2018
Thanks a lot Don

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Statistics and Machine Learning Toolbox finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by