finding Bias in dual form SVM using mean of support vector

7 ビュー (過去 30 日間)
Kien Tang
Kien Tang 2020 年 9 月 3 日
回答済み: Shubham Rawat 2020 年 9 月 14 日
Hi , here i am trying to implement Soft margin SVM using CVX
After getting the set of alpha using CVX i try to set the constrain of alpha to a set of support vector as S , then calculate the weight (w)
Now my problem is i want to calculate the bias b by using the mean of support vector but dont actually know how to implement that formula into matlab code
function dual = svm_train_dual(X_train, y_train, C)
%r = 800 , l = 200
[r,l] = size(X_train);
H = zeros(r,r);
q = ones(r,1);
for a = 1:r
for b = 1:r
H(a,b) = X_train(a,:)*X_train(b,:)';
end
end
cvx_begin
variable alp(r);
% minimize((1/2)*alp'*H*alp - q'*alp);
minimize(0.5*quad_form(y_train'.*alp,H) - q'*alp);
subject to
alp >= 0;
alp <= C/r;
y_train * alp == 0;
cvx_end
w = zeros(1,l);
b = 0;
%constraint alp to 1*10^-2 < alp < (C/r) - 1*10^-5 as a support vector
%S is set of support vector
S = alp(alp > 1*10^-5 | alp< (C/r) - 1*10^-5);
w = (S'.*y_train)*(X_train);
% S = alp(alp > 1*10^-5 | alp < (C/r) - 1*10^-5)
b = ?????????????;
dual.w = w;
dual.b = b;
dual.alp = alp;
dual.S = S;
end

回答 (1 件)

Shubham Rawat
Shubham Rawat 2020 年 9 月 14 日
Hi Kien,
Here Bias will be :
b = mean(y_train - w'*X_train);
% here you have already calculated weight vector

カテゴリ

Help Center および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by