Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hackassin
GitHub Repository: hackassin/Coursera-Machine-Learning
Path: blob/master/Week 2/Programming Assignment-1/computeCost.m
626 views
1
function J = computeCost(X, y, theta)
2
%COMPUTECOST Compute cost for linear regression
3
% J = COMPUTECOST(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
16
predictions = X * theta;
17
sqrErrors = (predictions - y).^2;
18
J = 1/(2*m) * sum(sqrErrors);
19
%printf("The size of J is\n");
20
%disp(size(J));
21
% =========================================================================
22
23
end
24
25