Completed task 2

This commit is contained in:
Sam Perry
2016-11-03 14:09:27 +00:00
parent 21b247a4e9
commit 1bc2e6c72f
3 changed files with 20 additions and 4 deletions
+1 -1
View File
@@ -14,4 +14,4 @@ function J = compute_cost(X, y, theta)
end end
J = J * (1.0 / (2 * m)); J = J * (1.0 / (2 * m));
end end
+1 -1
View File
@@ -11,4 +11,4 @@ iterations = 50;
do_plot = true; do_plot = true;
%% run gradient descent %% run gradient descent
t = gradient_descent(X, y, theta, alpha, iterations, do_plot); t = gradient_descent(X, y, theta, alpha, iterations, do_plot)
+18 -2
View File
@@ -1,5 +1,6 @@
%% This loads our data %% This loads our data
[X, y] = load_data_ex2(); [X, y] = load_data_ex2();
y
%% Normalise and initialize. %% Normalise and initialize.
[X, mean_vec, std_vec] = normalise_features(X); [X, mean_vec, std_vec] = normalise_features(X);
@@ -9,10 +10,25 @@ X = [ones(size(X, 1), 1), X];
%initialise theta %initialise theta
theta = [0.0, 0.0, 0.0]; theta = [0.0, 0.0, 0.0];
alpha = 0.1; alpha = 0.2;
iterations = 100; iterations = 100;
%% %%
t = gradient_descent(X, y, theta, alpha, iterations); t = gradient_descent(X, y, theta, alpha, iterations, false)
% Declare new pair of input features with which to calculate a predicted output
% value.
input_size = 3000.0;
input_bedrooms = 4.0;
% Normalize features
is_norm = (input_size - mean_vec(1)) / std_vec(1)
ib_norm = (input_bedrooms - mean_vec(2)) / std_vec(2)
% Use values for theta generated by gradient descent to predict the output
prediction = t(1) + t(2)*is_norm + t(3)*ib_norm;
% Round and print output
round(prediction)
disp 'Press enter to exit!'; disp 'Press enter to exit!';
pause; pause;