-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_svm.m
More file actions
21 lines (17 loc) · 701 Bytes
/
plot_svm.m
File metadata and controls
21 lines (17 loc) · 701 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function [ spatial_label ] = plot_svm( X, label, cl)
% Plot the the result of SVM
% Plot the data and the decision boundary
d = min(max(X(:,1)) - min(X(:,1)), max(X(:,2)) - min(X(:,2))) / 100;
[x1Grid,x2Grid] = meshgrid(min(X(:,1)):d:max(X(:,1)),min(X(:,2)):d:max(X(:,2)));
xGrid = [x1Grid(:),x2Grid(:)];
[~,scores] = predict(cl,xGrid);
h(1:2) = gscatter(X(:,1),X(:,2),label,'cb','.');
hold on
contour(x1Grid,x2Grid,reshape(scores(:,2),size(x1Grid)), [0, 0],'k');
legend(h,{'Negative','Positive'});
axis equal
axis([min(X(:,1)), max(X(:,1)), min(X(:,2)), max(X(:,2))])
hold off
% Compute the spatial label
spatial_label = predict(cl,X);
end