diff --git a/machine-learning-ex5/ex5/ex5.m b/machine-learning-ex5/ex5/ex5.m index 9af16eb..1df5a1c 100644 --- a/machine-learning-ex5/ex5/ex5.m +++ b/machine-learning-ex5/ex5/ex5.m @@ -54,7 +54,7 @@ fprintf(['Cost at theta = [1 ; 1]: %f '... '\n(this value should be about 303.993192)\n'], J); fprintf('Program paused. Press enter to continue.\n'); -pause; +% pause; %% =========== Part 3: Regularized Linear Regression Gradient ============= % You should now implement the gradient for regularized linear @@ -69,7 +69,7 @@ fprintf(['Gradient at theta = [1 ; 1]: [%f; %f] '... grad(1), grad(2)); fprintf('Program paused. Press enter to continue.\n'); -pause; +% pause; %% =========== Part 4: Train Linear Regression ============= @@ -94,7 +94,7 @@ plot(X, [ones(m, 1) X]*theta, '--', 'LineWidth', 2) hold off; fprintf('Program paused. Press enter to continue.\n'); -pause; +% pause; %% =========== Part 5: Learning Curve for Linear Regression ============= diff --git a/machine-learning-ex5/ex5/learningCurve.m b/machine-learning-ex5/ex5/learningCurve.m index 6ea4333..c1b6c3d 100644 --- a/machine-learning-ex5/ex5/learningCurve.m +++ b/machine-learning-ex5/ex5/learningCurve.m @@ -54,7 +54,12 @@ 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); +end diff --git a/machine-learning-ex5/ex5/linearRegCostFunction.m b/machine-learning-ex5/ex5/linearRegCostFunction.m index f07cb4c..a3c2d1e 100644 --- a/machine-learning-ex5/ex5/linearRegCostFunction.m +++ b/machine-learning-ex5/ex5/linearRegCostFunction.m @@ -33,7 +33,8 @@ J = temp1 + temp2; % ========================================================================= -t11 = sigmoid(X*theta) - y; +% t11 = sigmoid(X*theta) - y; +t11 = (X*theta) - y; t12 = repmat(t11, 1, size(X, 2)); temp11 = (1/m) * sum(X .* t12); diff --git a/machine-learning-ex5/ex5/sigmoid.m b/machine-learning-ex5/ex5/sigmoid.m index 34d19a1..6deca13 100644 --- a/machine-learning-ex5/ex5/sigmoid.m +++ b/machine-learning-ex5/ex5/sigmoid.m @@ -3,5 +3,4 @@ function g = sigmoid(z) % J = SIGMOID(z) computes the sigmoid of z. g = 1.0 ./ (1.0 + exp(-z)); -% g = z; end diff --git a/machine-learning-ex5/ex5/token.mat b/machine-learning-ex5/ex5/token.mat new file mode 100644 index 0000000..452c919 Binary files /dev/null and b/machine-learning-ex5/ex5/token.mat differ