Azzera filtri
Azzera filtri

qda plot please look at code

2 visualizzazioni (ultimi 30 giorni)
fafz1203
fafz1203 il 24 Set 2016
Commentato: fafz1203 il 24 Set 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;

Risposte (1)

Walter Roberson
Walter Roberson il 24 Set 2016
h2.LineStyle = 'none';
h2.Marker = '*';
  2 Commenti
fafz1203
fafz1203 il 24 Set 2016
Hey Walter, have you run my code?
fafz1203
fafz1203 il 24 Set 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;

Accedi per commentare.

Categorie

Scopri di più su Discrete Data Plots in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by