#NEWLINE# def _partial_fit( self , X , y , classes = None , _refit = False , sample_weight = None ) : #NEWLINE# #INDENT# 'Actual implementation of Gaussian NB fitting.\n\n        Parameters\n        ----------\n        X : array-like, 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\n        y : array-like, shape (n_samples,)\n            Target values.\n\n        classes : array-like, shape (n_classes,)\n            List of all the classes that can possibly appear in the y vector.\n\n            Must be provided at the first call to partial_fit, can be omitted\n            in subsequent calls.\n\n        _refit: bool\n            If true, act as though this were the first time we called\n            _partial_fit (ie, throw away any past fitting and start over).\n\n        sample_weight : array-like, shape (n_samples,), optional\n            Weights applied to individual samples (1. for unweighted).\n\n        Returns\n        -------\n        self : object\n            Returns self.\n        ' #NEWLINE# ( X , y ) = check_X_y ( X , y ) #NEWLINE# epsilon = ( 1e-09 * np . var ( X , axis = 0 ) . max ( ) ) #NEWLINE# if _refit : #NEWLINE# #INDENT# self . classes_ = None #NEWLINE# #UNINDENT# if _check_partial_fit_first_call ( self , classes ) : #NEWLINE# #INDENT# n_features = X . shape [ 1 ] #NEWLINE# n_classes = len ( self . classes_ ) #NEWLINE# self . theta_ = np . zeros ( ( n_classes , n_features ) ) #NEWLINE# self . sigma_ = np . zeros ( ( n_classes , n_features ) ) #NEWLINE# self . class_count_ = np . zeros ( n_classes , dtype = np . float64 ) #NEWLINE# n_classes = len ( self . classes_ ) #NEWLINE# if ( self . priors is not None ) : #NEWLINE# #INDENT# priors = np . asarray ( self . priors ) #NEWLINE# if ( len ( priors ) != n_classes ) : #NEWLINE# #INDENT# raise ValueError ( 'Number of priors must match number of classes.' ) #NEWLINE# #UNINDENT# if ( priors . sum ( ) != 1.0 ) : #NEWLINE# #INDENT# raise ValueError ( 'The sum of the priors should be 1.' ) #NEWLINE# #UNINDENT# if ( priors < 0 ) . any ( ) : #NEWLINE# #INDENT# raise ValueError ( 'Priors must be non-negative.' ) #NEWLINE# #UNINDENT# self . class_prior_ = priors #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . class_prior_ = np . zeros ( len ( self . classes_ ) , dtype = np . float64 ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( X . shape [ 1 ] != self . theta_ . shape [ 1 ] ) : #NEWLINE# #INDENT# msg = 'Number of features %d does not match previous data %d.' #NEWLINE# raise ValueError ( ( msg % ( X . shape [ 1 ] , self . theta_ . shape [ 1 ] ) ) ) #NEWLINE# #UNINDENT# self . sigma_ [ : , : ] -= epsilon #NEWLINE# #UNINDENT# classes = self . classes_ #NEWLINE# unique_y = np . unique ( y ) #NEWLINE# unique_y_in_classes = in1d ( unique_y , classes ) #NEWLINE# if ( not np . all ( unique_y_in_classes ) ) : #NEWLINE# #INDENT# raise ValueError ( ( 'The target label(s) %s in y do not exist in the initial classes %s' % ( y [ ( ~ unique_y_in_classes ) ] , classes ) ) ) #NEWLINE# #UNINDENT# for y_i in unique_y : #NEWLINE# #INDENT# i = classes . searchsorted ( y_i ) #NEWLINE# X_i = X [ ( y == y_i ) , : ] #NEWLINE# if ( sample_weight is not None ) : #NEWLINE# #INDENT# sw_i = sample_weight [ ( y == y_i ) ] #NEWLINE# N_i = sw_i . sum ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# sw_i = None #NEWLINE# N_i = X_i . shape [ 0 ] #NEWLINE# #UNINDENT# ( new_theta , new_sigma ) = self . _update_mean_variance ( self . class_count_ [ i ] , self . theta_ [ i , : ] , self . sigma_ [ i , : ] , X_i , sw_i ) #NEWLINE# self . theta_ [ i , : ] = new_theta #NEWLINE# self . sigma_ [ i , : ] = new_sigma #NEWLINE# self . class_count_ [ i ] += N_i #NEWLINE# #UNINDENT# self . sigma_ [ : , : ] += epsilon #NEWLINE# if ( self . priors is None ) : #NEWLINE# #INDENT# self . class_prior_ = ( self . class_count_ / self . class_count_ . sum ( ) ) #NEWLINE# #UNINDENT# return self