Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hackassin
GitHub Repository: hackassin/Coursera-Machine-Learning
Path: blob/master/Week 7/Programming Assignment - 6/ex6/visualizeBoundary.m
863 views
1
function visualizeBoundary(X, y, model, varargin)
2
%VISUALIZEBOUNDARY plots a non-linear decision boundary learned by the SVM
3
% VISUALIZEBOUNDARYLINEAR(X, y, model) plots a non-linear decision
4
% boundary learned by the SVM and overlays the data on it
5
6
% Plot the training data on top of the boundary
7
plotData(X, y)
8
9
% Make classification predictions over a grid of values
10
x1plot = linspace(min(X(:,1)), max(X(:,1)), 100)';
11
x2plot = linspace(min(X(:,2)), max(X(:,2)), 100)';
12
[X1, X2] = meshgrid(x1plot, x2plot);
13
vals = zeros(size(X1));
14
for i = 1:size(X1, 2)
15
this_X = [X1(:, i), X2(:, i)];
16
vals(:, i) = svmPredict(model, this_X);
17
end
18
19
% Plot the SVM boundary
20
hold on
21
contour(X1, X2, vals, [0.5 0.5], 'b');
22
hold off;
23
24
end
25
26