Gets the learning curve working.

This commit is contained in:
julien Lengrand-Lambert
2015-12-12 10:54:04 +01:00
parent 210a1d0b19
commit 78ede21908
5 changed files with 10 additions and 5 deletions

View File

@@ -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 =============

View File

@@ -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

View File

@@ -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);

View File

@@ -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

Binary file not shown.