Filter löschen
Filter löschen

qda plot please look at code

2 Ansichten (letzte 30 Tage)
fafz1203
fafz1203 am 24 Sep. 2016
Kommentiert: fafz1203 am 24 Sep. 2016
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;

Antworten (1)

Walter Roberson
Walter Roberson am 24 Sep. 2016
h2.LineStyle = 'none';
h2.Marker = '*';
  2 Kommentare
fafz1203
fafz1203 am 24 Sep. 2016
Hey Walter, have you run my code?
fafz1203
fafz1203 am 24 Sep. 2016
i want a full scatter plot of the two distributions and a quadratic decision boundary please take a look at this working code for a LINEAR decision boundary
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);
Class1 = 1; Class2 = 2; K = C.Coeffs(Class1, Class2).Const; L = C.Coeffs(Class1, Class2).Linear; f = @(x,y) K + [x y]*L;
hold on; ezplot(f, [min(X(:,1)) max(X(:,1)) min(X(:,2)) max(X(:,2))]); hold on;

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Discrete Data Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by