1
$\begingroup$

I have been using scikit-learn's LDA implementation to do some experiments, and recently wanted to test out some modifications to the LDA derivation. I was looking at the Python implementation that scikit-learn uses, and it was nearly unrecognizable given that I'm used to seeing LDA as maximizing the scatter between classes over the scatter within classes, formulated as an eigenvalue equation.

The source code for scikit-learn LDA is https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/lda.py

Is there an implementation of LDA out there in Python that might be more recognizable to me? i.e. it uses something more like http://www.ics.uci.edu/~welling/classnotes/papers_class/Fisher-LDA.pdf

$\endgroup$
  • $\begingroup$ That link doesn't work; the main reason I want a more standard LDA implementation is so that I can make some modifications to the algorithm and see what happens. $\endgroup$ – Andrew Latham Sep 23 '14 at 12:50
  • $\begingroup$ (corrected link - couldn't edit comment) It would seem better to learn what svd is: cs.utah.edu/~lifeifei/cis5930/lecture12-a.pdf . svd is a pretty standard way of diagonalising covariance matrices $\endgroup$ – seanv507 Sep 23 '14 at 12:54
  • $\begingroup$ (-1) This question is bordering on off-topic, as it is not about statistics but about a particular programming language. That said, why are you looking for such an implementation? If you understand the math and you know Python, you could easily write it yourself, it would not take more than ~20 lines of code. Still, here is one introduction to LDA with explicit Python example: implementing the LDA step-by-step in Python $\endgroup$ – amoeba Sep 24 '14 at 12:04
1
$\begingroup$

Well just reading an implementation of a mathematical concept can be really hard without good documentation. I came across this guide by Sebastian Raschka.

http://sebastianraschka.com/Articles/2014_python_lda.html

He moves step-by-step, explaining the concept, and writing the code. I think this answer might be too late for you, but may help others seeking this on the internet.

| cite | improve this answer | |
$\endgroup$
0
$\begingroup$

I think what might help is changing the 'solver' parameter from 'svd' (singular value decomposition, the default) to 'eigen'.

This should perform the discriminant analysis in the way you're more familiar with.

See: http://scikit-learn.org/stable/modules/generated/sklearn.discriminant_analysis.LinearDiscriminantAnalysis.html#sklearn.discriminant_analysis.LinearDiscriminantAnalysis

| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.