1
0
Fork 0

Learning curve function

master
neingeist 10 years ago
parent 90f2928cee
commit 1cc58802eb

@ -42,18 +42,34 @@ error_val = zeros(m, 1);
%
% Hint: You can loop over the examples with the following:
%
% for i = 1:m
% % Compute train/cross validation errors using training examples
% % X(1:i, :) and y(1:i), storing the result in
% % error_train(i) and error_val(i)
% ....
%
% end
for i = 1:m
% Compute train/cross validation errors using training examples
% X(1:i, :) and y(1:i), storing the result in
% error_train(i) and error_val(i)
X_ = X(1:i,:);
y_ = y(1:i);
% Train with regularization
lambda = 1;
theta = trainLinearReg(X_, y_, lambda);
% Compute the error with lambda = 0
lambda = 0;
error_train(i) = linearRegCostFunction(X_, y_, theta, lambda);
error_val(i) = linearRegCostFunction(Xval, yval, theta, lambda);
end
%
% ---------------------- Sample Solution ----------------------
% for i = 1:m
% % Compute train/cross validation errors using training examples
% % X(1:i, :) and y(1:i), storing the result in
% % error_train(i) and error_val(i)
% ....