Skip to content

Commit

Permalink
Update plotDecisionBoundary.m
Browse files Browse the repository at this point in the history
  • Loading branch information
malakar-soham authored Jul 31, 2019
1 parent 3a59c0e commit 74a99b5
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions plotDecisionBoundary.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@ function plotDecisionBoundary(theta, X, y)
% intercept.
% 2) MxN, N>3 matrix, where the first column is all-ones

% Plot Data
% Plotting Data
plotData(X(:,2:3), y);
hold on

if size(X, 2) <= 3
% Only need 2 points to define a line, so choose two endpoints
% Only need 2 points to define a line, so choosing two endpoints
plot_x = [min(X(:,2))-2, max(X(:,2))+2];

% Calculate the decision boundary line
% Calculating the decision boundary line
plot_y = (-1./theta(3)).*(theta(2).*plot_x + theta(1));

% Plot, and adjust axes for better viewing
% Plotting, and adjusting axes for better viewing
plot(plot_x, plot_y)

% Legend, specific for the exercise
legend('Admitted', 'Not admitted', 'Decision Boundary')
axis([30, 100, 30, 100])
else
Expand All @@ -31,16 +30,15 @@ function plotDecisionBoundary(theta, X, y)
v = linspace(-1, 1.5, 50);

z = zeros(length(u), length(v));
% Evaluate z = theta*x over the grid
% Evaluating z = theta*x over the grid
for i = 1:length(u)
for j = 1:length(v)
z(i,j) = mapFeature(u(i), v(j))*theta;
end
end
z = z'; % important to transpose z before calling contour

% Plot z = 0
% Notice you need to specify the range [0, 0]
% Plotting z = 0
contour(u, v, z, [0,0], 'LineWidth', 2)
end
hold off
Expand Down

0 comments on commit 74a99b5

Please sign in to comment.