Help req. in using fitcsvm()
1 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
Don Mathis
2018-5-11
编辑:Don Mathis
2018-5-11
(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 个评论
Don Mathis
2018-5-11
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)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!