Skip to content

Instantly share code, notes, and snippets.

@MariaLavrovskaya
Created October 18, 2021 10:42
Show Gist options
  • Save MariaLavrovskaya/ae5a02463331bf4f5c90b6db0b57f75c to your computer and use it in GitHub Desktop.
Save MariaLavrovskaya/ae5a02463331bf4f5c90b6db0b57f75c to your computer and use it in GitHub Desktop.
alphas = find(xPD>0.0001);
W=sum(xPD(alphas,:).*y(alphas,:).*x(alphas,:))
bias =mean( y(alphas,:) - x(alphas,:)*W')
% Xsupport=x((find(xPD~=0)),:);
% Ysupport=y((find(xPD~=0)),:);
Xsupport=x(alphas,:);
Ysupport=y(alphas,:);
hold on
scatter(x(y==1,1),x(y==1,2),'b')
scatter(x(y==-1,1),x(y==-1,2),'r')
scatter(Xsupport(Ysupport==1,1),Xsupport(Ysupport==1,2),'.b')
scatter(Xsupport(Ysupport==-1,1),Xsupport(Ysupport==-1,2),'.r')
syms x1 x2
fn=vpa((-bias-W(1)*x1)/W(2),6);
fn1=vpa((-1-bias-W(1)*x1)/W(2),6);
fn2=vpa((1-bias-W(1)*x1)/W(2),6);
fplot(fn,'Linewidth',3);
fplot(fn1,'Linewidth',1,'Color','g', 'LineStyle', '--');
fplot(fn2,'Linewidth',1,'Color','g', 'LineStyle', '--');
legend('Positive class', 'Negative Class', 'Support Vectors', 'Support Vectors', 'Decision Boundary', 'Margins', 'Location', 'best')
xlabel ('x1')
ylabel('y1')
hold off
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment