Issue 1:
Description

sklearn PCA with n_components = 'mle' and svd_solver = 'full' results in math domain error

The problem is in this line of code. The result of (spectrum[i] - spectrum[j]) is 0 and therefore i get log(0) which causes this exception.

Is this a sign of bad data or should the implementation handle this case?

Steps/Code to Reproduce

Store this in a file i.e. foo.csv

0.00000, 0.09204, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.99960, 0.99903, 0.28285, 0.28246, 1.00000, 0.00000, 0.00000, 0.92666, 0.82283, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000

0.00000, 0.09204, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.99991, 0.99934, 0.31101, 0.31064, 1.00000, 0.00000, 0.00000, 0.99241, 0.51799, 0.00000, 0.00000, 1.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000

0.00000, 0.09204, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.99991, 0.99934, 0.31101, 0.31064, 1.00000, 0.00000, 0.00000, 0.99241, 0.51799, 0.00000, 0.00000, 1.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000

0.00000, 0.09204, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.99991, 0.99934, 0.31101, 0.31064, 1.00000, 0.00000, 0.00000, 0.99241, 0.51799, 0.00000, 0.00000, 1.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000

0.00006, 0.09204, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.99920, 0.99863, 0.35419, 0.35384, 1.00000, 0.00000, 0.00000, 0.99421, 0.47923, 0.00000, 0.00000, 0.00000, 1.00000, 0.00000, 0.00000, 0.00000, 0.00000

1.00000, 0.11108, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.99144, 0.99088, 0.31786, 0.31748, 0.00000, 1.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.00000, 0.00000, 0.00000

0.00027, 0.35941, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.87935, 0.87885, 0.32529, 0.32492, 0.00000, 1.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000

0.00011, 0.09204, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00966, 0.99986, 0.99929, 0.35232, 0.35196, 1.00000, 0.00000, 0.00000, 0.98768, 0.53487, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000

0.00000, 0.09204, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.99882, 0.99825, 0.21965, 0.21922, 1.00000, 0.00000, 0.00000, 1.00000, 0.60636, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000

0.00027, 0.09204, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.99883, 0.99826, 0.33354, 0.33318, 1.00000, 0.00000, 0.00000, 0.99208, 0.51767, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.00000, 0.00000, 0.00000

0.00064, 0.38476, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.63538, 0.99263, 0.99207, 0.35795, 0.35759, 1.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.00000, 0.00000, 0.00000

0.00064, 0.38476, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.74959, 0.96602, 1.00000, 0.35795, 0.35759, 1.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.00000, 0.00000, 0.00000

0.00000, 0.11961, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.99962, 0.99906, 0.28849, 0.28810, 1.00000, 0.00000, 0.00000, 0.96794, 0.61479, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000

0.00018, 0.17423, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.99251, 0.99195, 0.39428, 0.39395, 0.00000, 1.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.00000, 0.00000, 0.00000

0.00041, 0.24312, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.98138, 0.99330, 0.99273, 0.40907, 0.40988, 0.00000, 0.00000, 1.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000

0.00007, 0.16128, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.25979, 0.99251, 0.99195, 0.41658, 0.41626, 0.00000, 1.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.00000, 0.00000, 0.00000

0.00000, 0.09204, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.99967, 0.99911, 0.34629, 0.34593, 0.00000, 1.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000

0.00069, 0.10755, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 0.00000, 0.99592, 0.99536, 0.00000, 0.00000, 1.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000

0.00091, 0.18421, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 1.00000, 1.00000, 0.00000, 0.00000, 0.92623, 0.82295, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000

0.00091, 0.18421, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 1.00000, 1.00000, 0.00000, 0.00000, 0.92623, 0.82295, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000

0.00000, 1.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.99998, 0.99941, 0.31381, 0.31343, 1.00000, 0.00000, 0.00000, 0.96963, 0.69883, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000

0.00000, 0.94950, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.99943, 0.31559, 0.31521, 1.00000, 0.00000, 0.00000, 0.92511, 0.68432, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000

0.00224, 0.89557, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.99999, 0.99942, 0.31477, 0.31439, 1.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000

0.00000, 0.79127, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.99943, 0.31602, 0.31580, 1.00000, 0.00000, 0.00000, 0.96963, 0.69883, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000

0.00000, 0.61136, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.99943, 0.31618, 0.31580, 1.00000, 0.00000, 0.00000, 0.96963, 0.69883, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000

0.00022, 0.19567, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.99943, 0.31477, 0.31439, 1.00000, 0.00000, 0.00000, 0.98541, 0.98441, 1.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000

import numpy
from sklearn.decomposition import PCA

test = numpy.genfromtxt("path/to/foo.csv", delimiter=',')
pca = PCA(n_components='mle', svd_solver='full')
data = pca.fit_transform(test) # This will produce the error

Expected Results

I expect data to have dimensions (X,Y) with X <= 26 and Y <=26

Actual Results

Traceback (most recent call last):

File "path/to/playground.py", line 13, in

data = pca.fit_transform(test) # This will produce the error

File "$path$\Python\Python36\lib\site-packages\sklearn\decomposition\pca.py", line 344, in fit_transform

U, S, V = self._fit(X)

File "$path$\Python\Python36\lib\site-packages\sklearn\decomposition\pca.py", line 388, in fit

return self.fit_full(X, n_components)

File "$path$\Python\Python36\lib\site-packages\sklearn\decomposition\pca.py", line 427, in fit_full

infer_dimension(explained_variance, n_samples, n_features)

File "$path$\Python\Python36\lib\site-packages\sklearn\decomposition\pca.py", line 103, in infer_dimension

ll[rank] = assess_dimension(spectrum, rank, n_samples, n_features)

File "$path$\Python\Python36\lib\site-packages\sklearn\decomposition\pca.py", line 88, in assess_dimension

(1. / spectrum[j] - 1. / spectrum[i])) + log(n_samples)

ValueError: math domain error

Versions

Windows-10-10.0.14393-SP0

Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:57:36) [MSC v.1900 64 bit (AMD64)]

NumPy 1.13.1

SciPy 0.19.1

Scikit-Learn 0.19.0

Side References

I asked a question regarding this problem on stackoverflow

Issue 2:
Sorry no show_versions output (yet to add to debian/rules, numpy 1.12.1), and I just wanted to possibly seek ideas/clues before digging deeper or skipping those tests - everything seems to be ok on more recentish systems:

1

____________________________ test_lars_cv_max_iter _____________________________

@pytest.mark.filterwarnings('ignore::FutureWarning')
def test_lars_cv_max_iter():
with warnings.catch_warnings(record=True) as w:
X = diabetes.data
y = diabetes.target
rng = np.random.RandomState(42)
x = rng.randn(len(y))
X = np.c_[X, x, x] # add correlated features
lars_cv = linear_model.LassoLarsCV(max_iter=5)
lars_cv.fit(X, y)
> assert_true(len(w) == 0)

re assert_true submitted #12547 - but anything sounds familiar?

2

__________________________ test_docstring_parameters ___________________________

@pytest.mark.filterwarnings('ignore::DeprecationWarning')
@pytest.mark.skipif(IS_PYPY, reason='test segfaults on PyPy')
def test_docstring_parameters():
# Test module docstring formatting
...
msg = '\n' + '\n'.join(sorted(list(set(incorrect))))
if len(incorrect) > 0:
> raise AssertionError("Docstring Error: " + msg)
E AssertionError: Docstring Error:
E sklearn.utils.fixes.divide arg mismatch: ['dtype', 'out', 'x1', 'x2']

sklearn/tests/test_docstring_parameters.py:125: AssertionError

so this one is particularly mysterious ;)

show_versions()

ATLAS version 3.10.3 built by buildd on Tue Jan 17 22:59:14 UTC 2017:
UNAME : Linux x86-ubc-01 3.16.0-4-amd64 #1 SMP Debian 3.16.39-1 (2016-12-30) x86_64 GNU/Linux
INSTFLG : -1 0 -a 1 -l 1
ARCHDEFS : -DATL_OS_Linux -DATL_ARCH_x86SSE2 -DATL_CPUMHZ=2297 -DATL_SSE2 -DATL_SSE1 -DATL_USE64BITS -DATL_GAS_x8664
F2CDEFS : -DAdd_ -DF77_INTEGER=int -DStringSunStyle
CACHEEDGE: 1048576
F77 : /usr/bin/x86_64-linux-gnu-gfortran, version GNU Fortran (Debian 6.3.0-2) 6.3.0 20161229
F77FLAGS : -fomit-frame-pointer -mfpmath=sse -O2 -msse2 -fPIC -m64
SMC : /usr/bin/gcc-6, version gcc-6 (Debian 6.3.0-2) 6.3.0 20161229
SMCFLAGS : -fomit-frame-pointer -mfpmath=sse -O2 -msse2 -fPIC -m64
SKC : /usr/bin/gcc-6, version gcc-6 (Debian 6.3.0-2) 6.3.0 20161229
SKCFLAGS : -fomit-frame-pointer -mfpmath=sse -O2 -msse2 -fPIC -m64

System
------
python: 2.7.13 (default, Nov 24 2017, 17:33:09) [GCC 6.3.0 20170516]
machine: Linux-4.16.0-0.bpo.2-amd64-x86_64-with-debian-9.5
executable: /usr/bin/python2.7

BLAS
----
macros: HAVE_CBLAS=None, ATLAS_INFO="\"3.10.3\""
cblas_libs: f77blas, cblas, atlas, f77blas, cblas
lib_dirs: /usr/lib/atlas-base

Python deps
-----------
Cython: None
scipy: 0.18.1
setuptools: 33.1.1
pip: None
numpy: 1.12.1
pandas: 0.22.0
sklearn: 0.20.0