Create LDA 2D and 3D plots
13 ビュー (過去 30 日間)
古いコメントを表示
Hello, I'm trying to perform Linear Discriminate Analysis (LDA) on 2 groups with 88 variables describing the groups. I would like to plot my data along with the line used to discriminate groups. The code below only allows me to plot the line, but not the points of the group. I am thinking this is similar to the 'score' output of PCA, but I can't find the analogous variable for this output. Please help!
MdlLinear = fitcdiscr(data,categories)
K = MdlLinear.Coeffs(1,2).Const;
L = MdlLinear.Coeffs(2,1).Linear;
f = @(x1,x2) K + L(1)*x1 + L(2)*x2;
figure %create 2D plot
di2 = ezplot(f)
figure %create 3D plot
d13 = fsurf(f)
2 件のコメント
Mor Guetta
2019 年 1 月 15 日
What I did was first plotting the data and using the 'hold on' function adding the line.
I'm new to this so there probably is a better way, but this works just fine.
figure()
scatter(x1,y1); % 1st group
hold on
scatter(x2,y2); % 2nd group
hold on
d = ezplot(f); % LDA margin
James Richard
2019 年 12 月 17 日
gscatter(x1,x2,class,'rb','.',10,'on','x1','x2');
% plot x1 and x2 data which grouped by class
% x1 color is red
% x2 color is blue
% markers are dot with size of 10
% legend is on
% x1 label is x2
% x2 label is x2
hold on
fimplicit(f);
"ezplot is not recommended as it behaves differently under different environments"
Use fimplicit instead to plot it.
Btw, there is a fault on your code.
K = MdlLinear.Coeffs(1,2).Const;
L = MdlLinear.Coeffs(2,1).Linear;
It should be the same!
K = MdlLinear.Coeffs(1,2).Const;
L = MdlLinear.Coeffs(1,2).Linear;
% or
K = MdlLinear.Coeffs(2,1).Const;
L = MdlLinear.Coeffs(2,1).Linear;
It could result into wrong boundaries!
回答 (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!