Plotting the decision boundary for logistic regression
10 views (last 30 days)
Show older comments
Hi, I am trying to run a logistic regression binary classification to predict the probability of the tumour being malignant or benign. I am new to this so sorry if they solution seems obvious, I just can't seem to figure out what is wrong. I've been following Andrew Ng's tutorials on Youtube to learn the mathematical concept and how to run the code in Matlab. The dataset I am using is simulated however it is based on the UCI Wisconsin breat cancer dataset. I have a problem when plotting the decision boundary, the decision boundary is reversed and I'm not sure why. I am only using 2 features to predict the probability of the tumour. I have attached the code and dataset.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/540586/image.png)
Any help is appreciated. Thank you in advance!
1 Comment
KA
on 11 Dec 2023
Hello Vivian,
I'm also working on the same data and I'm facing a few problems. If you have figured things out, could you kindly share the code with me? Thank you
Answers (1)
Vineet Joshi
on 23 Mar 2021
You can refer the following code to check your decision boundary for Logistic regression.
%Laod & Split Data
Data = load('Test.txt');
X = Data(:,1:2);
Y = categorical(Data(:,3));
%Fit Model
B = mnrfit(X,Y);
%Plot Decision Boundry
plot(X(:,1),-((B(1)*1 + B(2) * X(:,1))/B(3)));
The output will look as follows.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/559167/image.jpeg)
Since your training accuracy is also coming close to 63%, it is less likely the plotting of the boundary is an issue. You can try improving your current model or test some other models like SVM.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!