我想画一条曲线,用contour
分割这些二进制点。假设我找到了所有" svm"点和其他类似的论点:
X = [0.8169,1.3179;
1.5769,1.6961;
0.8577,1.8586;
0.8186,2.4992;
2.1778,0.9407;
1.1385,0.7873;
-0.6291,2.4245;
1.1454,1.0360;
1.6432,1.2201;
0.9730,2.1020;
2.7943,0.2780;
2.4555,0.7790;]
Y = [-1;
-1;
1;
-1;
1;
1;
1;
1;
-1;
-1;
-1;
-1;]
alpha = [ 100.0000;
12.6706;
100.0000;
8.4964;
100.0000;
20.4036;
1.1586;
51.9297;
63.0729;
38.1640;
35.2393;
15.8488;]
b = 3.080277010242503
C = 100
margin = 0.032448872572666
但我得到了这个结果。
如何让曲线将这些二进制点拆分为contour
?
这些是我的代码。
plot(X(find(Y>0),1), X(find(Y>0),2), 'bx', X(find(Y<0),1), X(find(Y<0),2), 'k.');
axis([-3 8 -3 8]);
title('soft SVM')
hold on
[x1, x2] = meshgrid(-2:0.1:7, -2:0.1:7);
[rows, cols] = size(x1);
nt = rows * cols;
Xt = [reshape(x1,1,nt); reshape(x2,1,nt)];
Z = sign(sum(bsxfun(@times, alpha .* Y, (X+margin)*(Xt+margin) )) + b);
Z = reshape(Z, rows, cols);
contour(x1,x2,Z,[0 0],'m');
hold off