Plotting the decision boundary for logistic regression

9 次查看(过去 30 天)
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 个评论
KA
KA 2023-12-11
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

请先登录,再进行评论。

回答(1 个)

Vineet Joshi
Vineet Joshi 2021-3-23
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.

类别

Help CenterFile Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by