Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hackassin
GitHub Repository: hackassin/Coursera-Machine-Learning
Path: blob/master/Week 2/Programming Assignment-1/computeCostMulti.m
626 views
1
function J = computeCostMulti(X, y, theta)
2
%COMPUTECOSTMULTI Compute cost for linear regression with multiple variables
3
% J = COMPUTECOSTMULTI(X, y, theta) computes the cost of using theta as the
4
% parameter for linear regression to fit the data points in X and y
5
6
% Initialize some useful values
7
m = length(y); % number of training examples
8
9
% You need to return the following variables correctly
10
J = 0;
11
12
% ====================== YOUR CODE HERE ======================
13
% Instructions: Compute the cost of a particular choice of theta
14
% You should set J to the cost.
15
%J = (1/2*m)*sum((X*theta-y)'*(X*theta-y));
16
%printf("Compute Cost\n");
17
%disp(J);
18
predictions = X * theta;
19
sqrErrors = (predictions - y).^2;
20
J = (1/(2*m)) * sum(sqrErrors);
21
printf("The size of J is\n");
22
disp(size(J));
23
printf("Compute Cost\n");
24
disp(J);
25
% =========================================================================
26
27
end
28
29