Error in logistic regression code
Ältere Kommentare anzeigen
Dear all,
I have X as 18 input and y as 1 output. When i ran the code than extra colmn occure in X? In X there should be 18 inputs but there occure 19 inputs why 1 extra colmn occure?
This is my main code. error in plotdecisionboundry(theta,X,Y)
data=xlsread('MyData');
X = data(:, [1:18]); y = data(:, 19)
fprintf(['Plotting data with + indicating (y = 1) examples and o ' ...
'indicating (y = 0) examples.\n']);
plotData(X, y);
hold on;
xlabel('Cough')
ylabel('Sputum')
legend('Positive', 'Negative')
hold off;
fprintf('\nProgram paused. Press enter to continue.\n
[m, n] = size(X);
X_test
X = [ones(m, 1) X];
initial_theta = zeros(n + 1, 1);
[cost, grad] = costFunction(initial_theta, X, y);
fprintf('Cost at initial theta (zeros): %f\n', cost);
fprintf('Gradient at initial theta (zeros): \n');
fprintf(' %f \n', grad);
fprintf('\nProgram paused. Press
options = optimset('GradObj', 'on', 'MaxIter', 400);
[theta, cost] = ...
fminunc(@(t)(costFunction(t, X, y)), initial_theta, options)
fprintf('Cost at theta found by fminunc: %f\n', cost);
fprintf('theta: \n');
fprintf(' %f \n', theta);
plotDecisionBoundary(theta, X, y);
hold on;
xlabel('Cough')
ylabel('Sputum')
legend('yes', 'no')
hold off;
fprintf('\nProgram paused. Press enter to continue.\n');
pause;
prob = sigmoid([1 1 1] * theta);
fprintf(['For a student with scores 45 and 85, we predict an admission ' ...
'probability of %f\n\n'], prob);
p = predict(theta, X);
fprintf('Train Accuracy: %f\n', mean(double(p == y)) * 100);
fprintf('\nProgram paused. Press e
This is the plot decision boundry code error in this line
Error. z(i,j) = mapFeature(u(i), v(j))*theta
Plot decision boundry code here
Plotdecisionboundry(theta,X,Y)
plotData(X(:,2:3), y);
hold on
if size(X, 2) <= 3
plot_x = [min(X(:,2))-2, max(X(:,2))+2];
plot_y = (-1./theta(3)).*(theta(2).*plot_x + theta(1));
plot(plot_x, plot_y)
legend('Admitted', 'Not admitted', 'Decision Boundary')
axis([30, 100, 30, 100])
else
u = linspace(-1, 1.5, 50);
v = linspace(-1, 1.5, 50);
z = zeros(length(u), length(v));
% Evaluate z = theta*x over the grid
for i = 1:length(u)
for j = 1:length(v)
z(i,j) = mapFeature(u(i), v(j))*theta;
end
end
z = z'; %
the range [0, 0]
contour(u, v, z, [0, 0], 'LineWidth', 2)
end
hold off
end
Akzeptierte Antwort
Weitere Antworten (3)
Tahira Mahar
am 28 Jul. 2018
0 Stimmen
1 Kommentar
Tahira Mahar
am 28 Jul. 2018
Bearbeitet: Tahira Mahar
am 28 Jul. 2018
Tahira Mahar
am 28 Jul. 2018
Bearbeitet: Walter Roberson
am 28 Jul. 2018
Tahira Mahar
am 28 Jul. 2018
Bearbeitet: Tahira Mahar
am 28 Jul. 2018
0 Stimmen
1 Kommentar
OCDER
am 30 Jul. 2018
Okay..... sooo... did you read, understand, and apply ANYTHING on that link? Did you take my advice on 26th? I even gave you a template, which I'm realizing might have been a waste of time...
What are you defending for again? We expect anyone with an academic degree to be able to : ask proper questions, learn quickly, apply knowledge to solve a problem, and communicate effectively.
The fact that you are posting comments on the "ANSWER" section, not starting a new Question on the forum as recommended, not providing a "FULL ERROR MESSAGE", not providing the script to generate the error, and demanding us to answer NOW baffles me...
If you need immediate help, kindly ask a colleage who knows Matlab, and make sure to BUY DINNER(S) for this person! It'll be much faster and you'll get to see the debugging process in person, which helps.
Kategorien
Mehr zu Introduction to Installation and Licensing finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!