From 74a99b54b72bf99bd3273c9d79d16085bcacb850 Mon Sep 17 00:00:00 2001 From: Soham Malakar Date: Wed, 31 Jul 2019 12:57:55 +0530 Subject: [PATCH] Update plotDecisionBoundary.m --- plotDecisionBoundary.m | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/plotDecisionBoundary.m b/plotDecisionBoundary.m index 4c7e0d1..b283d29 100644 --- a/plotDecisionBoundary.m +++ b/plotDecisionBoundary.m @@ -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 @@ -31,7 +30,7 @@ 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; @@ -39,8 +38,7 @@ function plotDecisionBoundary(theta, X, y) 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