SVM调优中超参数space的取值范围如何确定? (MATLAB)

How to decide the range for the hyperparameter space in SVM tuning? (MATLAB)

我正在使用 for 循环调整 SVM,以在超参数 space 的范围内进行搜索。 svm学习到的模型包含以下字段

   SVMModel: [1×1 ClassificationSVM]
          C: 2
FeaturesIdx: [4 6 8]
      Score: 0.0142

问题1)字段'score'的含义及其用途是什么?

问题2) 我正在调整BoxConstraint,C 值。假设特征的数量由变量 featsize 表示。变量 gridC 将包含搜索 space,它可以从任何值开始,例如 2^-5、2^-3 到 2^15 等。因此,gridC = 2.^(-5:2:15)。我不明白是否有办法 select 范围?

1. score 已在 here 中记录,它说:

Classification Score The SVM classification score for classifying observation x is the signed distance from x to the decision boundary ranging from -∞ to +∞. A positive score for a class indicates that x is predicted to be in that class. A negative score indicates otherwise.

在两个class案例中,如果有六个观测值,并且预测函数给了我们一些称为TestScore的分值,那么我们可以确定其中 class 进行以下归因的特定观察:

TestScore=[-0.4497    0.4497
           -0.2602    0.2602;
           -0.0746    0.0746;
            0.1070   -0.1070;
            0.2841   -0.2841;
            0.4566   -0.4566;];
[~,Classes] = max(TestScore,[],2);

在two-class class化中,我们也可以用find(TestScore > 0)代替,很明显前三个观察属于第二个class,第4到第6个观测值属于第一个class.

在多个class 案例 中,可能有多个分数 > 0,但代码 max(scores,[],2) 仍然有效。例如,我们可以使用下面的代码(来自 here,一个名为 Find Multiple Class Boundaries Using Binary SVM 的示例)来确定预测 Samples 的 classes。

for j = 1:numel(classes);
    [~,score] = predict(SVMModels{j},Samples);
    Scores(:,j) = score(:,2); % Second column contains positive-class scores
end
[~,maxScore] = max(Scores,[],2);

然后 maxScore 将表示每个样本的预测 classes。

2. BoxConstraint表示SVM模型中的C,所以我们可以在不同的超参数下训练SVM,select最好一个像这样:

gridC = 2.^(-5:2:15);
for ii=1:length(gridC)
SVModel = fitcsvm(data3,theclass,'KernelFunction','rbf',...
    'BoxConstraint',gridC(ii),'ClassNames',[-1,1]);
%if (%some constraints were meet) 
%  %save the current SVModel
%end
end

注意:另一种实现方法是使用 libsvm,一个快速且易于使用的 SVM 工具箱,它具有 MATLAB 的接口。