'Estimate model parameters with the EM algorithm.
A initialization step is performed before entering the
expectation-maximization (EM) algorithm. If you want to avoid
this step, set the keyword argument init_params to the empty
string \'\' when creating the GMM object. Likewise, if you would
like just to do an initialization, set n_iter=0.
Parameters
X : array_like, shape (n, n_features)
List of n_features-dimensional data points. Each row
corresponds to a single data point.
Returns
responsibilities : array, shape (n_samples, n_components)
Posterior probabilities of each mixture component for each
observation.'

def _fit(self, X, y=None, do_prediction=False):

    X = check_array(X, dtype=np.float64, ensure_min_samples=2, estimator=self)
    if (X.shape[0] < self.n_components):
        raise ValueError(('GMM    estimation    with    %s    components,    but    got    only    %s    samples' % (self.n_components, X.shape[0])))
    max_log_prob = (- np.infty)
    if (self.verbose > 0):
        print 'Expectation-maximization    algorithm    started.'
    for init in range(self.n_init):
        if (self.verbose > 0):
            print ('Initialization    ' + str((init + 1)))
            start_init_time = time()
        if (('m' in self.init_params) or (not hasattr(self, 'means_'))):
            self.means_ = cluster.KMeans(n_clusters=self.n_components, random_state=self.random_state).fit(X).cluster_centers_
            if (self.verbose > 1):
                print ' DCTB Means    have    been    initialized.'
        if (('w' in self.init_params) or (not hasattr(self, 'weights_'))):
            self.weights_ = np.tile((1.0 / self.n_components), self.n_components)
            if (self.verbose > 1):
                print ' DCTB Weights    have    been    initialized.'
        if (('c' in self.init_params) or (not hasattr(self, 'covars_'))):
            cv = (np.cov(X.T) + (self.min_covar * np.eye(X.shape[1])))
            if (not cv.shape):
                cv.shape = (1, 1)
            self.covars_ = distribute_covar_matrix_to_match_covariance_type(cv, self.covariance_type, self.n_components)
            if (self.verbose > 1):
                print ' DCTB Covariance    matrices    have    been    initialized.'
        current_log_likelihood = None
        self.converged_ = False
        for i in range(self.n_iter):
            if (self.verbose > 0):
                print (' DCTB EM    iteration    ' + str((i + 1)))
                start_iter_time = time()
            prev_log_likelihood = current_log_likelihood
            (log_likelihoods, responsibilities) = self.score_samples(X)
            current_log_likelihood = log_likelihoods.mean()
            if (prev_log_likelihood is not None):
                change = abs((current_log_likelihood - prev_log_likelihood))
                if (self.verbose > 1):
                    print (' DCTB  DCTB Change:    ' + str(change))
                if (change < self.tol):
                    self.converged_ = True
                    if (self.verbose > 0):
                        print ' DCTB  DCTB EM    algorithm    converged.'
                    break
            self._do_mstep(X, responsibilities, self.params, self.min_covar)
            if (self.verbose > 1):
                print ((' DCTB  DCTB EM    iteration    ' + str((i + 1))) + '    took    {0:.5f}s'.format((time() - start_iter_time)))
        if self.n_iter:
            if (current_log_likelihood > max_log_prob):
                max_log_prob = current_log_likelihood
                best_params = {'weights': self.weights_, 'means': self.means_, 'covars': self.covars_}
                if (self.verbose > 1):
                    print ' DCTB Better    parameters    were    found.'
        if (self.verbose > 1):
            print ((' DCTB Initialization    ' + str((init + 1))) + '    took    {0:.5f}s'.format((time() - start_init_time)))
    if (np.isneginf(max_log_prob) and self.n_iter):
        raise RuntimeError((('EM    algorithm    was    never    able    to    compute    a    valid    likelihood    ' + 'given    initial    parameters.    Try    different    init    parameters    ') + '(or    increasing    n_init)    or    check    for    degenerate    data.'))
    if self.n_iter:
        self.covars_ = best_params['covars']
        self.means_ = best_params['means']
        self.weights_ = best_params['weights']
    else:
        responsibilities = np.zeros((X.shape[0], self.n_components))
    return responsibilities
