How do I plot the W vector used in LDA?

Hi, I would like to plot some data, run LDA, and plot not only the discriminant , but also the W vector (orthogonal to the discriminator). I am interested in looking at the strength of the w vector when projected onto each axis.
I've tried the code below, which plots the discriminant, but I'm not sure how to access the W vector:
%
n=80; %number of data points in each class
info=ones(n,2); info(:,1)=2.4; info(:,2)=1.2;
X = [randn(n,2)+1; randn(n,2) + info];
Y = [ zeros(n,1); ones(n,1)];
gscatter(X(:,1),X(:,2),Y,['k','r'],'..',[16 16]);
% run lda -------------------------
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))]);
Any help is much appreciated!! Thank you again for all your help!!

Réponses (0)

Catégories

En savoir plus sur Statistics and Machine Learning Toolbox dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by