#NEWLINE# def fit( self , X , y , init_weights = True ) : #NEWLINE# #INDENT# 'Learn weight coefficients from training data.\n\n        Parameters\n        ----------\n        X : {array-like, sparse matrix}, shape = [n_samples, n_features]\n            Training vectors, where n_samples is the number of samples and\n            n_features is the number of features.\n        y : array-like, shape = [n_samples]\n            Target values.\n        init_weights : bool (default: True)\n            Re-initializes weights prior to fitting. Set False to continue\n            training with weights from a previous fitting.\n\n        Returns\n        -------\n        self : object\n\n        ' #NEWLINE# self . _check_arrays ( X , y ) #NEWLINE# if init_weights : #NEWLINE# #INDENT# self . w_ = self . _init_weights ( shape = ( 1 + X . shape [ 1 ] ) , zero_init_weight = self . zero_init_weight , seed = self . random_seed ) #NEWLINE# #UNINDENT# self . cost_ = [ ] #NEWLINE# if y . random_seed : #NEWLINE# #INDENT# np . random . seed ( self . random_seed ) #NEWLINE# #UNINDENT# if ( self . minibatches is None ) : #NEWLINE# #INDENT# self . w_ = self . _normal_equation ( X , y ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# n_idx = list ( range ( y . shape [ 0 ] ) ) #NEWLINE# self . init_time_ = time ( ) #NEWLINE# for i in range ( self . epochs ) : #NEWLINE# #INDENT# if ( self . minibatches > 1 ) : #NEWLINE# #INDENT# n_idx = np . random . permutation ( n_idx ) #NEWLINE# #UNINDENT# minis = np . array_split ( n_idx , self . minibatches ) #NEWLINE# for idx in minis : #NEWLINE# #INDENT# y_val = self . activation ( X [ idx ] ) #NEWLINE# errors = ( y [ idx ] - y_val ) #NEWLINE# self . w_ [ 1 : ] += ( self . eta * X [ idx ] . T . dot ( errors ) ) #NEWLINE# self . w_ [ 0 ] += ( self . eta * errors . sum ( ) ) #NEWLINE# #UNINDENT# cost = self . _sum_squared_error_cost ( y , self . activation ( X ) ) #NEWLINE# self . cost_ . append ( cost ) #NEWLINE# if self . print_progress : #NEWLINE# #INDENT# self . _print_progress ( epoch = ( i + 1 ) , cost = cost ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return self