1
0
Fork 0

Validation curve function

master
neingeist 10 years ago
parent 3751214442
commit 78830aaea7

@ -17,36 +17,36 @@ error_train = zeros(length(lambda_vec), 1);
error_val = zeros(length(lambda_vec), 1); error_val = zeros(length(lambda_vec), 1);
% ====================== YOUR CODE HERE ====================== % ====================== YOUR CODE HERE ======================
% Instructions: Fill in this function to return training errors in % Instructions: Fill in this function to return training errors in
% error_train and the validation errors in error_val. The % error_train and the validation errors in error_val. The
% vector lambda_vec contains the different lambda parameters % vector lambda_vec contains the different lambda parameters
% to use for each calculation of the errors, i.e, % to use for each calculation of the errors, i.e,
% error_train(i), and error_val(i) should give % error_train(i), and error_val(i) should give
% you the errors obtained after training with % you the errors obtained after training with
% lambda = lambda_vec(i) % lambda = lambda_vec(i)
% %
% Note: You can loop over lambda_vec with the following: % Note: You can loop over lambda_vec with the following:
% %
% for i = 1:length(lambda_vec) % for i = 1:length(lambda_vec)
% lambda = lambda_vec(i); % lambda = lambda_vec(i);
% % Compute train / val errors when training linear % % Compute train / val errors when training linear
% % regression with regularization parameter lambda % % regression with regularization parameter lambda
% % You should store the result in error_train(i) % % You should store the result in error_train(i)
% % and error_val(i) % % and error_val(i)
% .... % ....
% %
% end % end
% %
% %
for i = 1:length(lambda_vec)
lambda = lambda_vec(i);
theta = trainLinearReg(X, y, lambda);
lambda = 0;
error_train(i) = linearRegCostFunction(X, y, theta, lambda);
error_val(i) = linearRegCostFunction(Xval, yval, theta, lambda);
end
% ========================================================================= % =========================================================================