Regularization parameter in SVM in Matlab

I'm learning SVM in Matlab. Let be the hinge loss. I have data (X is a 200x2 matrix) and labels (Y is a 200x1 matrix). I want to use ‘fminunc.m’ to estimate the hyperplane that minimizes the hinge loss for different choices of λ. Here is my code in Matlab:
lambda = 1;
F = @(w)(w(1)^2+w(2)^2)+lambda*(max(0,1-sum(Y.*(w(1).*X(:,1)+w(2).*X(:,2)+w(3)))));
w0 = [0,0,0];
w = fminunc(F,w0);
y1 = (-w(:,1)*X(:,1)-w(3))/w(:,2);
plot (X(:,1),y1,'r', LineWidth', 2);
I tried to change the values of λ, however, the result (hyperplane parameters) hasn't changed. Are there any mistakes in the code?
Can anybody help with plotting the results on the data and the interpretation? Thank you.

 採用された回答

Matt J
Matt J 2018 年 11 月 19 日
編集済み: Matt J 2018 年 11 月 19 日

0 投票

Assuming this formula is correct
your coding of it
F = @(w)(w(1)^2+w(2)^2)+lambda*(max(0,1-sum(Y.*(w(1).*X(:,1)+w(2).*X(:,2)+w(3)))));
does not match. The equation has a summation outside of the max operation, but your code has the summation inside. Also, your equation has a leading term of w(2)^2, but your code has a leading term of w(1)^2 as well.
Finally, you need a differentiable substitute for max(0,x). Perhaps the softmax function?

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDeep Learning Toolbox についてさらに検索

製品

リリース

R2018a

タグ

質問済み:

2018 年 11 月 18 日

編集済み:

2018 年 11 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by