mirror of
https://github.com/jlengrand/MachineLearningCoursera.git
synced 2026-03-10 08:31:20 +00:00
Week 3
Finishes all mandatory exercises
This commit is contained in:
@@ -31,7 +31,7 @@ J = 1 / m * sum(part_1 - part_2);
|
||||
% Calculating g
|
||||
temp_1 = sigmoid(X*theta) - y;
|
||||
temp_2 = repmat(temp_1, 1, size(X, 2));
|
||||
g = 1/m * sum(X .* temp_2);
|
||||
grad = 1/m * sum(X .* temp_2);
|
||||
|
||||
% =============================================================
|
||||
|
||||
|
||||
@@ -17,10 +17,24 @@ grad = zeros(size(theta));
|
||||
% Compute the partial derivatives and set grad to the partial
|
||||
% derivatives of the cost w.r.t. each parameter in theta
|
||||
|
||||
% Calculating J
|
||||
theta_t_x = X*theta;
|
||||
h_theta = sigmoid(theta_t_x);
|
||||
|
||||
part_1 = -y'*log(h_theta);
|
||||
part_2 = (1 - y)' * log(1 - h_theta);
|
||||
part_3 = sum(theta(2:length(theta)).^2);
|
||||
%part_3 = sum(theta(2:length(theta)).*theta(2:length(theta)));
|
||||
|
||||
J = ((1 / m) * sum(part_1 - part_2)) + ((lambda/(2*m)) * part_3);
|
||||
|
||||
% Calculating g
|
||||
temp_1 = sigmoid(X*theta) - y;
|
||||
temp_2 = repmat(temp_1, 1, size(X, 2));
|
||||
|
||||
theta_vector = (lambda/m) * theta;
|
||||
theta_vector(1) = 0;
|
||||
grad = (1/m * sum(X .* temp_2))' + theta_vector;
|
||||
|
||||
% =============================================================
|
||||
|
||||
|
||||
@@ -15,11 +15,7 @@ p = zeros(m, 1);
|
||||
% You should set p to a vector of 0's and 1's
|
||||
%
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
p = sigmoid(X*theta) >= 0.5;
|
||||
|
||||
% =========================================================================
|
||||
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user