Plotting the decision boundary for logistic regression

8 vues (au cours des 30 derniers jours)
Vivian Chow
Vivian Chow le 6 Mar 2021
Commenté : KA le 11 Déc 2023
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!
  1 commentaire
KA
KA le 11 Déc 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

Connectez-vous pour commenter.

Réponses (1)

Vineet Joshi
Vineet Joshi le 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!

Translated by