필터 지우기
필터 지우기

qda plot please look at code

조회 수: 2 (최근 30일)
fafz1203
fafz1203 2016년 9월 24일
댓글: fafz1203 2016년 9월 24일
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;

답변 (1개)

Walter Roberson
Walter Roberson 2016년 9월 24일
h2.LineStyle = 'none';
h2.Marker = '*';
  댓글 수: 2
fafz1203
fafz1203 2016년 9월 24일
Hey Walter, have you run my code?
fafz1203
fafz1203 2016년 9월 24일
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;

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by