Description
I'm going to be using Gaussian Mixture Models for my research and I thought I would input some examples to see how the package worked. When I tried running the 1D Gaussian Mixture Example located here http://www.astroml.org/book_figures/chapter4/fig_GMM_1D.html it kicked back this error in Pycharm:
Traceback (most recent call last):
File "/home/jconaway/Research/Kepler_Analysis_2/gaussian_mixture_example.py", line 86, in
logprob, responsibilities = M_best.score_samples(x)
File "/home/jconaway/anaconda3/lib/python3.4/site-packages/sklearn/mixture/gmm.py", line 315, in score_samples
raise ValueError('The shape of X is not compatible with self')
ValueError: The shape of X is not compatible with self
Process finished with exit code 1
I figured it should have worked as-is, so I did some exploring as to why it wasn't working correctly. I found that when M_best.score_samples(x) reaches X = check_array(X) on line 309 of gmm.py, it looks like it doesn't return the correct array. Here's some doodling around I did with some arbitrary arrays:
In [1]: import numpy as np
In [2]: x = np.linspace(-3,3,7)
In [3]: y = x[:,np.newaxis]
In [4]: x
Out[4]: array([-3., -2., -1., 0., 1., 2., 3.])
In [5]: y
Out[5]:
array([[-3.],
[-2.],
[-1.],
[ 0.],
[ 1.],
[ 2.],
[ 3.]])
In [6]: y.shape[1]
Out[6]: 1
In [7]: from sklearn.utils import validation
In [8]: Q = np.array([1,2,3,4,5])
In [9]: q = validation.check_array(Q)
In [10]: q
Out[10]: array([[1, 2, 3, 4, 5]])
In [11]: s = q[:,np.newaxis]
In [12]: s
Out[12]: array([[[1, 2, 3, 4, 5]]])
When I went back to the example and changed it to this:
s = x[:,np.newaxis]
logprob, responsibilities = M_best.score_samples(s)
it worked fine. That's as far as I've gotten with this. Hope it's helpful.