From 86f13105ee1edd569fff132fac60fb4633395cd8 Mon Sep 17 00:00:00 2001 From: Carldeboer Date: Wed, 10 Jun 2015 18:05:01 -0400 Subject: [PATCH] Added error messages in case user provides one dimensional means_ or data (X) When trying to learn a GMM on one dimensional data, both weights and the data can be represented as 1-d vectors. However, this breaks GMM.fit() and it used to die with cryptic error messages. This addition specifically checks for one dimensional input and issues an error accordingly. --- sklearn/mixture/gmm.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sklearn/mixture/gmm.py b/sklearn/mixture/gmm.py index bb2a3fed630e5..6021df6ce854c 100644 --- a/sklearn/mixture/gmm.py +++ b/sklearn/mixture/gmm.py @@ -461,6 +461,12 @@ def _fit(self, X, y=None, do_prediction=False): observation. """ + if len(self.means_.shape)<2: + raise ValueError( + 'GMM means_ is one dimensional. use reshape(means_,(-1,1))') + if len(X.shape)<2: + raise ValueError( + 'X is one dimensional. use reshape(X,(-1,1))') # initialization step X = check_array(X, dtype=np.float64) if X.shape[0] < self.n_components: