Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hackassin
GitHub Repository: hackassin/Coursera-Machine-Learning
Path: blob/master/Week 2/Octave Tutorial/5. Control & Methods/costFunction.m
625 views
1
function J = costFunction(X, y, theta)
2
3
% X is the design-matrix cosnisting of the training examples
4
% y is the matrix consisting of the actual values
5
% theta is the constant variable used in hypothesis function
6
7
m = size(X,1);
8
disp("No. of training examples");
9
disp(m);
10
predictions = X * theta; %hypothesis function
11
disp("Predictions");
12
disp(predictions);
13
sqrErrors = (predictions-y).^2; %squared errors
14
disp("Squared Errors");
15
disp(sqrErrors);
16
J = 1/(2*m) * sum(sqrErrors);
17