#NEWLINE# def fit( self , X , y = None ) : #NEWLINE# #INDENT# 'Estimate model parameters with the EM algorithm.\n\n        The method fit the model `n_init` times and set the parameters with\n        which the model has the largest likelihood or lower bound. Within each\n        trial, the method iterates between E-step and M-step for `max_iter`\n        times until the change of likelihood or lower bound is less than\n        `tol`, otherwise, a `ConvergenceWarning` is raised.\n\n        Parameters\n        ----------\n        X : array-like, shape (n_samples, n_features)\n            List of n_features-dimensional data points. Each row\n            corresponds to a single data point.\n\n        Returns\n        -------\n        self\n        ' #NEWLINE# X = _check_X ( X , self . n_components ) #NEWLINE# self . _check_initial_parameters ( X ) #NEWLINE# do_init = ( not ( self . warm_start and hasattr ( self , 'converged_' ) ) ) #NEWLINE# n_init = ( self . n_init if do_init else 1 ) #NEWLINE# max_log_likelihood = ( - np . infty ) #NEWLINE# self . converged_ = False #NEWLINE# for init in range ( n_init ) : #NEWLINE# #INDENT# self . _print_verbose_msg_init_beg ( init ) #NEWLINE# if do_init : #NEWLINE# #INDENT# self . _initialize_parameters ( n_init ) #NEWLINE# #UNINDENT# ( current_log_likelihood , resp ) = self . _e_step ( X ) #NEWLINE# for n_iter in range ( self . max_iter ) : #NEWLINE# #INDENT# prev_log_likelihood = current_log_likelihood #NEWLINE# self . _m_step ( X , resp ) #NEWLINE# ( current_log_likelihood , resp ) = self . _e_step ( X ) #NEWLINE# change = ( current_log_likelihood - prev_log_likelihood ) #NEWLINE# self . _print_verbose_msg_iter_end ( n_iter , change ) #NEWLINE# if ( abs ( change ) < self . tol ) : #NEWLINE# #INDENT# self . converged_ = True #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# self . _print_verbose_msg_init_end ( current_log_likelihood ) #NEWLINE# if ( current_log_likelihood > max_log_likelihood ) : #NEWLINE# #INDENT# max_log_likelihood = current_log_likelihood #NEWLINE# best_params = self . _get_parameters ( ) #NEWLINE# best_n_iter = n_iter #NEWLINE# #UNINDENT# #UNINDENT# if ( not self . converged_ ) : #NEWLINE# #INDENT# warnings . warn ( ( 'Initialization %d did not converged. Try different init parameters, or increase n_init, tol or check for degenerate data.' % ( init + 1 ) ) , ConvergenceWarning ) #NEWLINE# #UNINDENT# self . _set_parameters ( best_params ) #NEWLINE# self . n_iter_ = best_n_iter #NEWLINE# return self