scikit-learn/scikit-learn — pull request #2847 by zyv (2014-02-11 13:48:07+00:00)
Title: FIX: make K-Means accept 1D vectors

Other unsupervised learning implementations, such as GMM accept 1D vectors as input. K-Means, however, expects a 2D array, because 1D vectors are mangled by atleast2d_or_csr(). I think that this should be fixed for consistency: either all should *not* accept 1D vectors, or all should accept them.

I'm not sure what is the best way to do this, but here is my take: I copy-pasted the check from GMM, but wrapped it into a try / except statement, because apparently it's not a good idea to run asarray() on the array_like, since atleast2d_or_csr() is used as an input check. So I check from the ndim == 1, if there is no such attribute, then this check is a nop.

Hope this helps!