#NEWLINE# def fit( self , X , y , sample_weight = None ) : #NEWLINE# #INDENT# 'Build a forest of trees from the training set (X, y).\n\n        Parameters\n        ----------\n        X : array-like or sparse matrix of shape = [n_samples, n_features]\n            The training input samples. Internally, it will be converted to\n            ``dtype=np.float32`` and if a sparse matrix is provided\n            to a sparse ``csc_matrix``.\n\n        y : array-like, shape = [n_samples] or [n_samples, n_outputs]\n            The target values (class labels in classification, real numbers in\n            regression).\n\n        sample_weight : array-like, shape = [n_samples] or None\n            Sample weights. If None, then samples are equally weighted. Splits\n            that would create child nodes with net zero or negative weight are\n            ignored while searching for a split in each node. In the case of\n            classification, splits are also ignored if they would result in any\n            single class carrying a negative weight in either child node.\n\n        Returns\n        -------\n        self : object\n            Returns self.\n        ' #NEWLINE# X = check_array ( X , accept_sparse = 'csc' , dtype = DTYPE ) #NEWLINE# y = check_array ( y , accept_sparse = 'csc' , ensure_2d = False , dtype = None ) #NEWLINE# if issparse ( X ) : #NEWLINE# #INDENT# X . sort_indices ( ) #NEWLINE# #UNINDENT# ( n_samples , self . n_features_ ) = X . shape #NEWLINE# y = np . atleast_1d ( y ) #NEWLINE# if ( ( y . ndim == 2 ) and ( y . shape [ 1 ] == 1 ) ) : #NEWLINE# #INDENT# warn ( 'A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples,), for example using ravel().' , DataConversionWarning , stacklevel = 2 ) #NEWLINE# #UNINDENT# if ( y . ndim == 1 ) : #NEWLINE# #INDENT# y = np . reshape ( y , ( ( - 1 ) , 1 ) ) #NEWLINE# #UNINDENT# self . n_outputs_ = y . shape [ 1 ] #NEWLINE# ( y , expanded_class_weight ) = self . _validate_y_class_weight ( y ) #NEWLINE# if ( ( getattr ( y , 'dtype' , None ) != DOUBLE ) or ( not y . flags . contiguous ) ) : #NEWLINE# #INDENT# y = np . ascontiguousarray ( y , dtype = DOUBLE ) #NEWLINE# #UNINDENT# if ( expanded_class_weight is not None ) : #NEWLINE# #INDENT# if ( sample_weight is not None ) : #NEWLINE# #INDENT# sample_weight = ( sample_weight * expanded_class_weight ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# sample_weight = expanded_class_weight #NEWLINE# #UNINDENT# #UNINDENT# self . _validate_estimator ( ) #NEWLINE# if ( ( not self . bootstrap ) and self . oob_score ) : #NEWLINE# #INDENT# raise ValueError ( 'Out of bag estimation only available if bootstrap=True' ) #NEWLINE# #UNINDENT# random_state = check_random_state ( self . random_state ) #NEWLINE# if ( not self . warm_start ) : #NEWLINE# #INDENT# self . estimators_ = [ ] #NEWLINE# #UNINDENT# n_more_estimators = ( self . n_estimators - len ( self . estimators_ ) ) #NEWLINE# if ( n_more_estimators < 0 ) : #NEWLINE# #INDENT# raise ValueError ( ( 'n_estimators=%d must be larger or equal to len(estimators_)=%d when warm_start==True' % ( self . n_estimators , len ( self . estimators_ ) ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( n_more_estimators == 0 ) : #NEWLINE# #INDENT# warn ( 'Warm-start fitting without increasing n_estimators does not fit new trees.' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( self . warm_start and ( len ( self . estimators_ ) > 0 ) ) : #NEWLINE# #INDENT# random_state . randint ( MAX_INT , size = len ( self . estimators_ ) ) #NEWLINE# #UNINDENT# trees = [ ] #NEWLINE# for i in range ( n_more_estimators ) : #NEWLINE# #INDENT# tree = self . _make_estimator ( append = False ) #NEWLINE# tree . set_params ( random_state = random_state . randint ( MAX_INT ) ) #NEWLINE# trees . append ( tree ) #NEWLINE# #UNINDENT# trees = Parallel ( n_jobs = self . n_jobs , verbose = self . verbose , backend = 'threading' ) ( ( delayed ( _parallel_build_trees ) ( t , self , X , y , sample_weight , i , len ( trees ) , verbose = self . verbose , class_weight = self . class_weight ) for ( i , t ) in enumerate ( trees ) ) ) #NEWLINE# self . estimators_ . extend ( trees ) #NEWLINE# #UNINDENT# #UNINDENT# if self . oob_score : #NEWLINE# #INDENT# self . _set_oob_score ( X , y ) #NEWLINE# #UNINDENT# if ( hasattr ( self , 'classes_' ) and ( self . n_outputs_ == 1 ) ) : #NEWLINE# #INDENT# self . n_classes_ = self . n_classes_ [ 0 ] #NEWLINE# self . classes_ = self . classes_ [ 0 ] #NEWLINE# #UNINDENT# return self