Skip to content

Commit 68b4ba5

Browse files
author
Merouane Atig
committed
Calculate training error ok
1 parent 1f0207f commit 68b4ba5

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

mlclass-ex5/learningCurve.m

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,15 @@
5555

5656
% ---------------------- Sample Solution ----------------------
5757

58+
theta_val = trainLinearReg(Xval, yval, lambda);
5859
for i = 1:m
5960
Xset = X(1:i, :);
6061
yset = y(1:i);
61-
theta = trainLinearReg(Xset, yset, lambda);
62-
error_train(i) = linearRegCostFunction(Xset, yset, theta, 0);
63-
theta = trainLinearReg(Xval(1:i, :), yval(1:i), lambda);
64-
error_val(i) = linearRegCostFunction(Xval, yval, theta, 0);
62+
theta_set = trainLinearReg(Xset, yset, lambda);
63+
error_train(i) = linearRegCostFunction(Xset, yset, theta_set, 0);
64+
Xset = Xval(1:i, :);
65+
yset = yval(1:i);
66+
error_val(i) = linearRegCostFunction(Xset, yset, theta_val, 0);
6567
end
6668

6769

0 commit comments

Comments
 (0)