|
|
@ -49,18 +49,20 @@ X = [ones(m, 1) X];
|
|
|
|
% initial_theta, options);
|
|
|
|
% initial_theta, options);
|
|
|
|
%
|
|
|
|
%
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for c = 1:num_labels
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
% Train a one-vs all classifier for this class c
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
initial_theta = zeros(n + 1, 1);
|
|
|
|
|
|
|
|
options = optimset('GradObj', 'on', 'MaxIter', 50);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[theta] = fmincg(@(t)(lrCostFunction(t, X, (y == c), lambda)),
|
|
|
|
|
|
|
|
initial_theta, options);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
all_theta(c,:) = theta';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
% =========================================================================
|
|
|
|
% =========================================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|