Elffuss BraidHub

kikocis/auto-code-rover public

main · 2.3 KiBRawPermalink
1GaussianMixture predict and fit_predict disagree when n_init>1
2#### Description
3When `n_init` is specified in GaussianMixture, the results of fit_predict(X) and predict(X) are often different. The `test_gaussian_mixture_fit_predict` unit test doesn't catch this because it does not set `n_init`.
4
5#### Steps/Code to Reproduce
6```
7python
8from sklearn.mixture import GaussianMixture
9from sklearn.utils.testing import assert_array_equal
10import numpy
11X = numpy.random.randn(1000,5)
12print 'no n_init'
13gm = GaussianMixture(n_components=5)
14c1 = gm.fit_predict(X)
15c2 = gm.predict(X)
16assert_array_equal(c1,c2)
17print 'n_init=5'
18gm = GaussianMixture(n_components=5, n_init=5)
19c1 = gm.fit_predict(X)
20c2 = gm.predict(X)
21assert_array_equal(c1,c2)
22```
23
24#### Expected Results
25```
26no n_init
27n_init=5
28```
29No exceptions.
30
31#### Actual Results
32```
33no n_init
34n_init=5
35Traceback (most recent call last):
36 File "test_gm.py", line 17, in <module>
37 assert_array_equal(c1,c2)
38 File "/home/scott/.local/lib/python2.7/site-packages/numpy/testing/_private/utils.py", line 872, in assert_array_equal
39 verbose=verbose, header='Arrays are not equal')
40 File "/home/scott/.local/lib/python2.7/site-packages/numpy/testing/_private/utils.py", line 796, in assert_array_compare
41 raise AssertionError(msg)
42AssertionError:
43Arrays are not equal
44
45(mismatch 88.6%)
46 x: array([4, 0, 1, 1, 1, 3, 3, 4, 4, 2, 0, 0, 1, 2, 0, 2, 0, 1, 3, 1, 1, 3,
47 2, 1, 0, 2, 1, 0, 2, 0, 3, 1, 2, 3, 3, 1, 0, 2, 2, 0, 3, 0, 2, 0,
48 4, 2, 3, 0, 4, 2, 4, 1, 0, 2, 2, 1, 3, 2, 1, 4, 0, 2, 2, 1, 1, 2,...
49 y: array([4, 1, 0, 2, 2, 1, 1, 4, 4, 0, 4, 1, 0, 3, 1, 0, 2, 2, 1, 2, 0, 0,
50 1, 0, 4, 1, 0, 4, 0, 1, 1, 2, 3, 1, 4, 0, 1, 4, 4, 4, 0, 1, 0, 2,
51 4, 1, 1, 2, 4, 3, 4, 0, 2, 3, 2, 3, 0, 0, 2, 3, 3, 3, 3, 0, 3, 2,...
52```
53
54#### Versions
55```
56System:
57 python: 2.7.15rc1 (default, Nov 12 2018, 14:31:15) [GCC 7.3.0]
58 machine: Linux-4.15.0-43-generic-x86_64-with-Ubuntu-18.04-bionic
59executable: /usr/bin/python
60
61BLAS:
62 macros: HAVE_CBLAS=None, NO_ATLAS_INFO=-1
63cblas_libs: cblas
64 lib_dirs: /usr/lib/x86_64-linux-gnu
65
66Python deps:
67 Cython: 0.28.5
68 scipy: 1.2.0
69setuptools: 39.0.1
70 pip: 19.0.1
71 numpy: 1.16.0
72 pandas: 0.23.1
73 sklearn: 0.20.2
74```