qda plot please look at code
2 views (last 30 days)
Show older comments
Can anyone check what is wrong with this code? I want to plot a Quadratic Discriminant Analysis with a scatter plot instead I'm just getting a slightly curved line, please ignore the comments,
mu2 = [3 3];
s1 = [1 .5; .5 2];
s2 = [1 .5; .5 2];
R = chol(s1);
T = chol(s2);
tsmp1 = repmat(mu1, 1000, 1) + randn(1000,2)*R;
sampleY1 = zeros(1000,1);
% Step 3: sampleY2 means it is the label of tsmp2
tsmp2 = repmat(mu2, 1000, 1) + randn(1000,2)*T;
sampleY2 = ones(1000,1);
X = [tsmp1; tsmp2];
Y = [sampleY1; sampleY2];
gscatter(X(:,1), X(:,2), Y);
% Step1, if you want to use this method, you need two thing:
% - X as training data
% - Y as label
% C = ClassificationDiscriminant.fit(X,Y);
MdlQuadratic = fitcdiscr(X,Y,'DiscrimType','quadratic');
Class1 = 1;
Class2 = 2;
K = MdlQuadratic.Coeffs(Class1,Class2).Const;
L = MdlQuadratic.Coeffs(Class1,Class2).Linear;
Q = MdlQuadratic.Coeffs(Class1,Class2).Quadratic;
f = @(x1,x2) K + L(1)*x1 + L(2)*x2 + Q(1,1)*x1.^2 + ...
(Q(1,2)+Q(2,1))*x1.*x2 + Q(2,2)*x2.^2;
h2 = ezplot(f,[.9 7.1 0 2.5]);
h2.Color = 'r';
h2.LineWidth = 2;
0 Comments
Answers (1)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!