Code covered by the BSD License  

Highlights from
LDA: Linear Discriminant Analysis

4.42857

4.4 | 7 ratings Rate this file 308 Downloads (last 30 days) File Size: 1.95 KB File ID: #29673

LDA: Linear Discriminant Analysis

by

 

Performs linear discriminant analysis.

| Watch this File

File Information
Description

Features of this implementation of LDA:
- Allows for >2 classes
- Permits user-specified prior probabilities
- Requires only base MATLAB (no toolboxes needed)
- Assumes that the data is complete (no missing values)
- Has been verified against statistical software
- "help LDA" provides usage and an example, including conditional probability calculation

Note: This routine always includes the prior probability adjustment to the linear score functions. (Some other LDA software drops this when the user specifies equal prior probabilities.)

MATLAB release MATLAB 7.10 (R2010a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (13)
07 Feb 2014 tiene filisbino

I did not understand the matrix w!
Can you explain it?

16 Dec 2013 Lu

thanks for your program

05 Sep 2013 Ghulam Rasool  
07 Mar 2013 Qasem

Thank you for your program.

But I agree with maryam, after you find the coefficients for the training data, it should be used to test and classify another data which is missed the class label.
It is great if it is contains a testing part.

@ Christian Johner: where is the file?

16 May 2012 Joon  
23 Mar 2012 Robert Preusche

it might be worth to mention will's blogspot entry where he explains the code in some more detail and also answers some interesting questions:
http://matlabdatamining.blogspot.de/2010/12/linear-discriminant-analysis-lda.html

thanks for the code, will!

02 Feb 2012 Greg Fichter

I'm an utter beginner with LDA, but I'm getting quite different class probability results using this vs. the 'classify' routine from the statistics toolbox. Perhaps it's the prior probability adjustment, but it would be nice if this had a literature reference and/or comparable results to classify.

29 Nov 2011 Christian Johner

@maryam faal: how it is done is shown in the file.

03 Aug 2011 sun

very good

30 Jun 2011 oberstein ova

Hello Mr Dwinnell,

I’m oberstein, PHD student of university of Paris.

Thank you very much for your share of your LDA (discriminant analysis) code, I find it on the web of Matlab center, it is very useful for me, yours is more intelligent than mine o(∩_∩)o

But there are some things of your code that I don’t understand, Can I ask you three questions about your LDA code?

Thank you at first!

1 For Accumulate pooled covariance information, why do you use ((nGroup(i) - 1) / (n - k) ) in “PooledCov = PooledCov + ((nGroup(i) - 1) / (n - k) ).* cov(Input(Group,:))”? Why it isn’t nGroup(i)/ n or nGroup(i)/ n-1 witch we use often in the probability? Can you tell me the raison or the theory with ((nGroup(i) - 1) / (n - k) )?

2 I don’t quite understand you Matrix W.

2-1) In the LDA, we find at first Sw (with-in-class scatter matrix) and Sb (between-class scatter matrix), and then we can find the eigenvectors of inv(Sw)*Sb, isn’t it? What is your matrix W? Is it the eigenvectors? – I don’t think so. Is it the matrix inv(Sw)*Sb? – But why you add the term log(PriorProb(i))?

2-2) Can you tell me something about the term log(PriorProb(i)) ? I don’t understand why it is here in W(:,1). Is it for the linear regression?

3 For calculate class probabilities at last, why do you use exponent? P=exp(L)./repmat(sum(exp(L),2),[1 2]), it can’t be L./ repmat(sum(L),2),[1 2]) ? I don’t understand why we must use the exponent to calculate the probabilities.

Thank you very much
Best Regards

oberstein

13 Apr 2011 maryam faal

you said that input is training sample then how did you classify the test sample?

07 Apr 2011 Will Dwinnell

Input and Target are both from the training data. "Input" is a matrix containing the independent variables, while "Target" contains the dependent variable.

06 Apr 2011 maryam faal

Dear Will
Thanks for your program but I have a question about it
"Input" and "Target" are training samples or test samples?

Contact us