| 1 | diff --git a/sklearn/mixture/base.py b/sklearn/mixture/base.py |
| 2 | --- a/sklearn/mixture/base.py |
| 3 | +++ b/sklearn/mixture/base.py |
| 4 | @@ -172,7 +172,7 @@ def _initialize(self, X, resp): |
| 5 | def fit(self, X, y=None): |
| 6 | """Estimate model parameters with the EM algorithm. |
| 7 | |
| 8 | - The method fit the model `n_init` times and set the parameters with |
| 9 | + The method fits the model `n_init` times and set the parameters with |
| 10 | which the model has the largest likelihood or lower bound. Within each |
| 11 | trial, the method iterates between E-step and M-step for `max_iter` |
| 12 | times until the change of likelihood or lower bound is less than |
| 13 | @@ -188,6 +188,32 @@ def fit(self, X, y=None): |
| 14 | ------- |
| 15 | self |
| 16 | """ |
| 17 | + self.fit_predict(X, y) |
| 18 | + return self |
| 19 | + |
| 20 | + def fit_predict(self, X, y=None): |
| 21 | + """Estimate model parameters using X and predict the labels for X. |
| 22 | + |
| 23 | + The method fits the model n_init times and sets the parameters with |
| 24 | + which the model has the largest likelihood or lower bound. Within each |
| 25 | + trial, the method iterates between E-step and M-step for `max_iter` |
| 26 | + times until the change of likelihood or lower bound is less than |
| 27 | + `tol`, otherwise, a `ConvergenceWarning` is raised. After fitting, it |
| 28 | + predicts the most probable label for the input data points. |
| 29 | + |
| 30 | + .. versionadded:: 0.20 |
| 31 | + |
| 32 | + Parameters |
| 33 | + ---------- |
| 34 | + X : array-like, shape (n_samples, n_features) |
| 35 | + List of n_features-dimensional data points. Each row |
| 36 | + corresponds to a single data point. |
| 37 | + |
| 38 | + Returns |
| 39 | + ------- |
| 40 | + labels : array, shape (n_samples,) |
| 41 | + Component labels. |
| 42 | + """ |
| 43 | X = _check_X(X, self.n_components, ensure_min_samples=2) |
| 44 | self._check_initial_parameters(X) |
| 45 | |
| 46 | @@ -240,7 +266,7 @@ def fit(self, X, y=None): |
| 47 | self._set_parameters(best_params) |
| 48 | self.n_iter_ = best_n_iter |
| 49 | |
| 50 | - return self |
| 51 | + return log_resp.argmax(axis=1) |
| 52 | |
| 53 | def _e_step(self, X): |
| 54 | """E step. |