scikit-learn/scikit-learn — Issue #661: PCA fails with n_components='mle' when  n_features > n_samples
Author: brentp
Created: 2012-02-29 22:02:03+00:00
State: open

Here is code to reproduce the error with git @ 6783466. The tests only have the case where n_features <= n_samples

```python

from sklearn.decomposition import PCA
from numpy.random import randn

X = randn(100, 10)
PCA(n_components='mle').fit(X) # OK

PCA(n_components='mle').fit(X.T) # ERROR
```

The error is in the _assess_dimension function.

```
Traceback (most recent call last):
File "t.py", line 9, in
PCA(n_components='mle').fit(X.T) # ERROR
File "/usr/local/src/scikit-learn/sklearn/decomposition/pca.py", line 192, in fit
self._fit(X, **params)
File "/usr/local/src/scikit-learn/sklearn/decomposition/pca.py", line 240, in _fit
n_samples, X.shape[1])
File "/usr/local/src/scikit-learn/sklearn/decomposition/pca.py", line 88, in _infer_dimension_
ll.append(_assess_dimension_(spectrum, rank, n, p))
File "/usr/local/src/scikit-learn/sklearn/decomposition/pca.py", line 72, in _assess_dimension_
pa += (np.log((spectrum[i] - spectrum[j])
IndexError: index out of bounds

```