Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GMM estimation ValueError #2

Open
hongxuchen opened this issue Sep 29, 2015 · 6 comments
Open

GMM estimation ValueError #2

hongxuchen opened this issue Sep 29, 2015 · 6 comments

Comments

@hongxuchen
Copy link

In 04.3-Density-GMM.ipynb of In [3], it complains at clf = GMM(4, n_iter=500, random_state=3).fit(x) that:

/usr/local/lib/python2.7/dist-packages/sklearn/mixture/gmm.pyc in fit(self, X, y)
    433             raise ValueError(
    434                 'GMM estimation with %s components, but got only %s samples' %
--> 435                 (self.n_components, X.shape[0]))

Can you please tell what's going on? Thanks!

@jakevdp
Copy link
Owner

jakevdp commented Sep 29, 2015

You're probably passing a 1D array to a function expecting a 2D array.

@hongxuchen
Copy link
Author

Strange. But I was exactly following this notebook (i.e., by copy-paste). Sorry I'm a newbie and this question must be silly.

@ghost
Copy link

ghost commented Apr 15, 2016

Hi Jake. There was a change in scikit learn, and now one dimensional data is no longer allowed (as in x = np.concatenate([np.random.normal(0, 2, 2000), np.random.normal(5, 5, 2000), np.random.normal(3, 0.5, 600)]) from the ipynb.

The reason was that it was not clear if one dimensional data was supposed to mean many samples of one feature or one sample of many features. The error mentioned by @hongxuchen is easily corrected by passing x.reshape((-1,1)) but for some reason this gives a lower quality output from GMM.

I am still waiting an answer from the awesome scikit learn team, but do you know what changes could be done (initialization parameters, maybe) in order to get the same plot in your notebook? Thanks! :)

@jakevdp
Copy link
Owner

jakevdp commented Apr 15, 2016

I've fixed this is the updated tutorial: http://github.com/jakevdp/sklearn_tutorial

Sorry about this: with the amount of material I have out there, it's impossible to keep everything up-to-date with ever-changing APIs. The only sustainable fix would be to delete old repositories, but I'd rather not do that.

@ghost
Copy link

ghost commented Apr 15, 2016

Thanks Jake. I was following this set of notebooks because it is from the last pycon. Not a bullet proof solution but maybe adding a small warning and a reference to your actively maintained tutorial could work. Thanks again for the fast answer

@jakevdp
Copy link
Owner

jakevdp commented Apr 15, 2016

Done, in the README

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants