This commit is contained in:
2017-05-28 20:20:47 +09:00
parent 4620fe8652
commit a1fda7be43
6 changed files with 41 additions and 17 deletions

View File

@@ -164,7 +164,7 @@ pause;
% lambda to see how the fit and learning curve change.
%
lambda = 0;
lambda = 3;
[theta] = trainLinearReg(X_poly, y, lambda);
% Plot training data and fit
@@ -218,3 +218,11 @@ end
fprintf('Program paused. Press enter to continue.\n');
pause;
%% Computing test set error
lambda = 3;
[theta] = trainLinearReg(X_poly, y, lambda);
testSetError = linearRegCostFunction(X_poly_test, ytest, theta, 0);
fprintf('#Test Set Error for lambda(%f) : %f\n', lambda, testSetError);

View File

@@ -53,11 +53,13 @@ error_val = zeros(m, 1);
% ---------------------- Sample Solution ----------------------
for i = 1:m
[theta] = trainLinearReg(X(1:i, :), y(1:i), lambda);
error_train(i) = linearRegCostFunction(X(1:i, :), y(1:i), theta, 0);
error_val(i) = linearRegCostFunction(Xval, yval, theta, 0);
endfor
% -------------------------------------------------------------

View File

@@ -21,8 +21,9 @@ grad = zeros(size(theta));
hx = X*theta;
J = sum((hx - y).**2)/(2*m) + lambda*sum((theta(2:end).**2))/(2*m);
grad = (sum((hx-y).*X)/m)' + lambda*[0; theta(2:end)]/m;

View File

@@ -15,10 +15,8 @@ X_poly = zeros(numel(X), p);
%
%
for i = 1:p
X_poly(:, i) = X.^i;
% =========================================================================

15
ex5/token.mat Normal file
View File

@@ -0,0 +1,15 @@
# Created by Octave 4.2.1, Sun May 28 20:19:23 2017 GMT <unknown@unknown>
# name: email
# type: sq_string
# elements: 1
# length: 16
mjjo53@gmail.com
# name: token
# type: sq_string
# elements: 1
# length: 16
9vAaPE4tKr9tF716

View File

@@ -39,14 +39,14 @@ error_val = zeros(length(lambda_vec), 1);
%
%
for i = 1:length(lambda_vec)
lambda = lambda_vec(i);
[theta] = trainLinearReg(X, y, lambda);
error_train(i) = linearRegCostFunction(X, y, theta, 0);
error_val(i) = linearRegCostFunction(Xval, yval, theta, 0);
endfor
% =========================================================================