mirror of
https://github.com/jlengrand/MachineLearningCoursera.git
synced 2026-03-10 08:31:20 +00:00
Gets the learning curve working.
This commit is contained in:
@@ -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 =============
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
BIN
machine-learning-ex5/ex5/token.mat
Normal file
BIN
machine-learning-ex5/ex5/token.mat
Normal file
Binary file not shown.
Reference in New Issue
Block a user