Cost Function, Linear Regression, trying to avoid hard coding theta. Octave.

You can use vectorize of operations in Octave/Matlab.
Iterate over entire vector – it is really bad idea, if your programm language let you vectorize operations.
R, Octave, Matlab, Python (numpy) allow this operation.
For example, you can get scalar production, if theta = (t0, t1, t2, t3) and X = (x0, x1, x2, x3) in the next way:
theta * X’ = (t0, t1, t2, t3) * (x0, x1, x2, x3)’ = t0*x0 + t1*x1 + t2*x2 + t3*x3
Result will be scalar.

For example, you can vectorize h in your code in the next way:

H = (theta'*X')';
S = sum((H - y) .^ 2);
J = S / (2*m);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)