Cursera: machine learning ex6.
This commit is contained in:
24
machine_learning/mlclass-ex6-008/mlclass-ex6/visualizeBoundary.m
Executable file
24
machine_learning/mlclass-ex6-008/mlclass-ex6/visualizeBoundary.m
Executable file
@@ -0,0 +1,24 @@
|
||||
function visualizeBoundary(X, y, model, varargin)
|
||||
%VISUALIZEBOUNDARY plots a non-linear decision boundary learned by the SVM
|
||||
% VISUALIZEBOUNDARYLINEAR(X, y, model) plots a non-linear decision
|
||||
% boundary learned by the SVM and overlays the data on it
|
||||
|
||||
% Plot the training data on top of the boundary
|
||||
plotData(X, y)
|
||||
|
||||
% Make classification predictions over a grid of values
|
||||
x1plot = linspace(min(X(:,1)), max(X(:,1)), 100)';
|
||||
x2plot = linspace(min(X(:,2)), max(X(:,2)), 100)';
|
||||
[X1, X2] = meshgrid(x1plot, x2plot);
|
||||
vals = zeros(size(X1));
|
||||
for i = 1:size(X1, 2)
|
||||
this_X = [X1(:, i), X2(:, i)];
|
||||
vals(:, i) = svmPredict(model, this_X);
|
||||
end
|
||||
|
||||
% Plot the SVM boundary
|
||||
hold on
|
||||
contour(X1, X2, vals, [0 0], 'Color', 'b');
|
||||
hold off;
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user