Completed task 2
This commit is contained in:
@@ -11,4 +11,4 @@ iterations = 50;
|
||||
do_plot = true;
|
||||
|
||||
%% run gradient descent
|
||||
t = gradient_descent(X, y, theta, alpha, iterations, do_plot);
|
||||
t = gradient_descent(X, y, theta, alpha, iterations, do_plot)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
%% This loads our data
|
||||
[X, y] = load_data_ex2();
|
||||
y
|
||||
|
||||
%% Normalise and initialize.
|
||||
[X, mean_vec, std_vec] = normalise_features(X);
|
||||
@@ -9,10 +10,25 @@ X = [ones(size(X, 1), 1), X];
|
||||
|
||||
%initialise theta
|
||||
theta = [0.0, 0.0, 0.0];
|
||||
alpha = 0.1;
|
||||
alpha = 0.2;
|
||||
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!';
|
||||
pause;
|
||||
|
||||
Reference in New Issue
Block a user