我正在 coursera 上学习 ML 类(class),我的 SVMtraining 代码是正确的,但图表与 pdf 中提供的解决方案不匹配。我不明白我的代码中为什么或有什么问题。
以下是我的解决方案。我还附上了图表,第一个是提供的解决方案,另一个是我的。 enter image description here enter image description here
function [C, sigma] = dataset3Params(X, y, Xval, yval)
C = 1;
sigma = 0.3;
vals= [0.01 0.03 0.1 0.3 1 3 10 30];
err=1000000000;
for i=1:8
for j= 1:8
ex_C=vals(i);
ex_sigma=vals(j);
model=svmTrain(X, y, ex_C, @(x1,x2) gaussianKernel(x1,x2,ex_sigma));
predictions = svmPredict(model, Xval);
sam_err= mean(double(predictions ~= yval));
if sam_err <= err
C=ex_C;
sigma=ex_sigma;
err=sam_err;
end
end
end
最佳答案
轮廓应为contour(X1, X2, vals, [0.5 0.5], 'b');
关于machine-learning - SVM 训练的稍微倾斜的图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39930995/