-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
LDA.explained_variance_ratio_ is of the wrong size #6032
Copy link
Copy link
Closed
Labels
BugEasyWell-defined and straightforward way to resolveWell-defined and straightforward way to resolve
Milestone
Description
The docs say that LDA.explained_variance_ratio_ should have only n_components_. But it doesn't.
It looks like this bug only exists when we use the eigen solver, not the svd solver.
>>> import numpy as np
>>> from sklearn.lda import LDA
>>> from sklearn.utils.testing import assert_equal
>>>
>>> state = np.random.RandomState(0)
>>> X = state.normal(loc=0, scale=100, size=(40, 20))
>>> y = state.randint(0, 3, size=(40, 1))
>>>
>>> # Train the LDA classifier. Use the eigen solver
>>> lda_eigen = LDA(solver='eigen', n_components=5)
>>> lda_eigen.fit(X, y)
>>> assert_equal(lda_eigen.explained_variance_ratio_.shape, (5,))
AssertionError: Tuples differ: (20,) != (5,)
First differing element 0:
20
5
- (20,)
+ (5,)
Looks like we fix either the docs or the code. Which one?
Pinging @JPFrancoia.
Addresses an issue in #6031.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugEasyWell-defined and straightforward way to resolveWell-defined and straightforward way to resolve