|
|
@ -6,16 +6,18 @@ function J = computeCost(X, y, theta)
|
|
|
|
% Initialize some useful values
|
|
|
|
% Initialize some useful values
|
|
|
|
m = length(y); % number of training examples
|
|
|
|
m = length(y); % number of training examples
|
|
|
|
|
|
|
|
|
|
|
|
% You need to return the following variables correctly
|
|
|
|
% You need to return the following variables correctly
|
|
|
|
J = 0;
|
|
|
|
J = 0;
|
|
|
|
|
|
|
|
|
|
|
|
% ====================== YOUR CODE HERE ======================
|
|
|
|
% ====================== YOUR CODE HERE ======================
|
|
|
|
% Instructions: Compute the cost of a particular choice of theta
|
|
|
|
% Instructions: Compute the cost of a particular choice of theta
|
|
|
|
% You should set J to the cost.
|
|
|
|
% You should set J to the cost.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
predictions = X * theta;
|
|
|
|
|
|
|
|
errors = predictions - y;
|
|
|
|
|
|
|
|
squared_errors = errors .^ 2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
J = 1/(2*m) * sum(squared_errors);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
% =========================================================================
|
|
|
|
% =========================================================================
|
|
|
|
|
|
|
|
|
|
|
|