Plotting the decision boundary for logistic regression

59 views (last 30 days)
Vivian Chow
Vivian Chow on 6 Mar 2021
Answered: Vineet Joshi on 23 Mar 2021
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.
Any help is appreciated. Thank you in advance!

Answers (1)

Vineet Joshi
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.
Where mnrfit is used to perform Multinomial Logistic Regression in MATLAB.
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.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!