![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/173554/image.bmp)
Plotting 3 Dimensional Class boundaries of LDA in Matlab
15 次查看(过去 30 天)
显示 更早的评论
Hi guys, I'm doing some classification research and looking into LDA. For now I'm researching Fisher's iris Data that id built into matlab. I understand when it is 2 dimensional the plotting of the boundary lines is quite straight forward. However if I use 3 dimensions I'm not quite sue how to plot the boundary lines. I've used the example on mathworks, for 2-dimensions and this is not a problem (<http://uk.mathworks.com/help/stats/discriminant-analysis.html)>.
I've attached a matlab plot of the 3 features I'm looking to use from the data, what I'm looking to get is a plane across the 3 features that separates the data into its different classes, in this example I'd need 2 planes. This is what is used for 2D
endMdlLinear.ClassNames([2 3])
K = MdlLinear.Coeffs(2,3).Const;
L = MdlLinear.Coeffs(2,3).Linear;
f = @(x1,x2) K + L(1)*x1 + L(2)*x2;
h2 = ezplot(f,[.9 7.1 0 2.5]);
h2.Color = 'r';
h2.LineWidth = 2;
Any help would be appreciated.
0 个评论
回答(1 个)
Omanshu Thapliyal
2017-3-28
It would be recommended to use fsurf instead of 'ezplot' as it would help you plot a 3d plane, as you require.
Assuming that you have 2 Gaussian random vectors X1 and x2, here's how you could perform LDA and then plots a discriminant plane between the two sets.
X = [X1;X2];
MdlLinear = fitcdiscr(X,c);
K = MdlLinear.Coeffs(1,2).Const;
L = MdlLinear.Coeffs(2,1).Linear;
f = @(x1,x2) K + L(1)*x1 + L(2)*x2;
fsurf(f,'FaceColor',[1 0 0],'EdgeColor','none');
alpha = 0.5;
The script above produces the plot attached:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/173554/image.bmp)
0 个评论
另请参阅
类别
在 Help Center 和 File 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!