Skip to content

LinearDiscriminantAnalysis, explained variance ratio superior to one #9107

Closed

Description

@Cdk29

Hi !

I am performing PCA and LDA on several micro-array data, with a y label vector for various mutant and an X matrix for the genes expression (see below), with a code similar to the example provide on
http://scikit-learn.org/stable/auto_examples/decomposition/plot_pca_vs_lda.html#sphx-glr-auto-examples-decomposition-plot-pca-vs-lda-py

All the PCA works well, but few LDA output an Explained variance ratio superior to one. I suspect some float error in the array return by the lda object created by the following code and poor data not allowing to get a good explained variance :

    nb_class=nb_class_count(y)
    
    lda = LinearDiscriminantAnalysis(solver="eigen", shrinkage="auto", n_components=2)
    X_r2 = lda.fit(X, y).transform(X)       
    lda2 = LinearDiscriminantAnalysis(solver="eigen", shrinkage="auto")
    X_r3 = lda2.fit(X, y).transform(X) 


    print "nb_class", nb_class        
    print "lda.explained_variance_ratio_", lda.explained_variance_ratio_      
    print "lda2.explained_variance_ratio_", lda2.explained_variance_ratio_

Return :

nb_class 4
lda.explained_variance_ratio_ [ 1.29840783 1.0474278 ]
lda2.explained_variance_ratio_ [ 1.29840783 1.0474278 0.98598958]

Where X and y are :

X [[-0.0381006 0.0107296 -0.0463756 ..., -0.520574 0.201947 0.372232 ]
[-0.0800158 0.0292747 0.203857 ..., -0.405826 0.532436 -0.310816 ]
[ 0.118346 -0.10846 0.0856565 ..., 0.414698 -0.464304 -0.308325 ]
...,
[-0.0624702 -0.145009 0.240819 ..., -0.366957 -0.518862 -0.379997 ]
[-0.108163 0.114644 0.141642 ..., 0.0443211 2.91074 3.74194 ]
[-0.169948 -0.158028 0.186845 ..., 0.289508 3.44199 2.14646 ]]

y [ 3. 3. 2. ..., 0. 0. 0.]

Linux-4.9.0-3-amd64-x86_64-with-debian-9.0
('Python', '2.7.13 (default, Jan 19 2017, 14:48:08) \n[GCC 6.3.0 20170118]')
('NumPy', '1.12.1')
('SciPy', '0.18.1')
('Scikit-Learn', '0.18.1')

Nonetheless, I become suspicious for all my results now. Is there a way to assess the exact number of the explained ratio ?

Tell me if you need any more code.

Activity

  1. changed the title [-]Lda, explained variance ratio superior to one[/-] [+]LinearDiscriminantAnalysis, explained variance ratio superior to one[/+] on Jun 14, 2017
  2. amueller commented on May 22, 2018

    @amueller
    Member

    This indeed looks fishy :-/ is this still true on master and regardless of solver?

  3. glemaitre commented on May 17, 2024

    @glemaitre
    Member

    Closing this issue because we will not be able to address it without a reproducible.
    Maybe #9400 will be more helpful for a reproducer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions