diff --git a/ex1/computeCost.m b/ex1/computeCost.m index 93eb14c..c68149a 100644 --- a/ex1/computeCost.m +++ b/ex1/computeCost.m @@ -13,7 +13,8 @@ J = 0; % Instructions: Compute the cost of a particular choice of theta % You should set J to the cost. - +hx = X*theta; +J = sum((hx - y).^2)/(2*m); diff --git a/ex1/computeCostMulti.m b/ex1/computeCostMulti.m index d9a3d68..d34c970 100644 --- a/ex1/computeCostMulti.m +++ b/ex1/computeCostMulti.m @@ -14,7 +14,8 @@ J = 0; % You should set J to the cost. - +hx = X*theta; +J = sum((hx - y).^2)/(2*m); % ========================================================================= diff --git a/ex1/ex1_multi.m b/ex1/ex1_multi.m index f733012..f1de379 100644 --- a/ex1/ex1_multi.m +++ b/ex1/ex1_multi.m @@ -105,7 +105,7 @@ fprintf('\n'); % Recall that the first column of X is all-ones. Thus, it does % not need to be normalized. price = 0; % You should change this - +price = [1, 1650, 3]*theta; % ============================================================ @@ -150,7 +150,7 @@ fprintf('\n'); % Estimate the price of a 1650 sq-ft, 3 br house % ====================== YOUR CODE HERE ====================== price = 0; % You should change this - +price = [1, 1650, 3]*theta; % ============================================================ diff --git a/ex1/featureNormalize.m b/ex1/featureNormalize.m index bb5d072..3d1d262 100644 --- a/ex1/featureNormalize.m +++ b/ex1/featureNormalize.m @@ -26,9 +26,10 @@ sigma = zeros(1, size(X, 2)); % Hint: You might find the 'mean' and 'std' functions useful. % - - - +mu = mean(X); +X_norm .-= mu; +sigma = std(X); +X_norm ./= sigma; diff --git a/ex1/gradientDescent.m b/ex1/gradientDescent.m index 57b4d3c..9e8fc59 100644 --- a/ex1/gradientDescent.m +++ b/ex1/gradientDescent.m @@ -18,7 +18,8 @@ for iter = 1:num_iters % - + hx = X*theta; + theta -= (alpha*sum((hx-y).*X)/m)'; diff --git a/ex1/gradientDescentMulti.m b/ex1/gradientDescentMulti.m index e5e1b7e..56f6978 100644 --- a/ex1/gradientDescentMulti.m +++ b/ex1/gradientDescentMulti.m @@ -20,7 +20,8 @@ for iter = 1:num_iters - + hx = X*theta; + theta -= (alpha*sum((hx-y).*X)/m)'; diff --git a/ex1/normalEqn.m b/ex1/normalEqn.m index d32cd8e..9f36913 100644 --- a/ex1/normalEqn.m +++ b/ex1/normalEqn.m @@ -12,7 +12,7 @@ theta = zeros(size(X, 2), 1); % ---------------------- Sample Solution ---------------------- - +theta = pinv(X'*X)*X'*y; % ------------------------------------------------------------- diff --git a/ex1/plotData.m b/ex1/plotData.m index f50a677..889c69e 100644 --- a/ex1/plotData.m +++ b/ex1/plotData.m @@ -17,7 +17,9 @@ figure; % open a new figure window % markers larger by using plot(..., 'rx', 'MarkerSize', 10); - +plot(x, y, 'rx', 'MarkerSize', 10); +ylabel('Profit in $10,000s'); +xlabel('Population of City in 10,000s'); % ============================================================ diff --git a/ex1/token.mat b/ex1/token.mat new file mode 100644 index 0000000..09c81b0 --- /dev/null +++ b/ex1/token.mat @@ -0,0 +1,15 @@ +# Created by Octave 4.2.1, Sun May 28 17:11:16 2017 GMT +# name: email +# type: sq_string +# elements: 1 +# length: 16 +mjjo53@gmail.com + + +# name: token +# type: sq_string +# elements: 1 +# length: 16 +9Dxrb898sAaadc8j + + diff --git a/ex1/warmUpExercise.m b/ex1/warmUpExercise.m index 4ab8187..524f568 100644 --- a/ex1/warmUpExercise.m +++ b/ex1/warmUpExercise.m @@ -11,7 +11,7 @@ A = []; - +A = eye(5);