#NEWLINE# def _set_oob_score( self , X , y ) : #NEWLINE# #INDENT# 'Compute out-of-bag score' #NEWLINE# X = check_array ( X , dtype = DTYPE , accept_sparse = 'csr' ) #NEWLINE# n_classes_ = self . n_classes_ #NEWLINE# n_samples = y . shape [ 0 ] #NEWLINE# oob_decision_function = [ ] #NEWLINE# oob_score = 0.0 #NEWLINE# predictions = [ ] #NEWLINE# for k in range ( self . n_outputs_ ) : #NEWLINE# #INDENT# predictions . append ( np . zeros ( ( n_samples , n_classes_ [ k ] ) ) ) #NEWLINE# #UNINDENT# for estimator in self . estimators_ : #NEWLINE# #INDENT# unsampled_indices = _generate_unsampled_indices ( estimator . random_state , n_samples ) #NEWLINE# p_estimator = estimator . predict_proba ( X [ unsampled_indices , : ] , check_input = False ) #NEWLINE# if ( self . n_outputs_ == 1 ) : #NEWLINE# #INDENT# p_estimator = [ p_estimator ] #NEWLINE# #UNINDENT# for k in range ( self . n_outputs_ ) : #NEWLINE# #INDENT# predictions [ k ] [ unsampled_indices , : ] += p_estimator [ k ] #NEWLINE# #UNINDENT# #UNINDENT# for k in range ( self . n_outputs_ ) : #NEWLINE# #INDENT# if ( predictions [ k ] . sum ( axis = 1 ) == 0 ) . any ( ) : #NEWLINE# #INDENT# warn ( 'Some inputs do not have OOB scores. This probably means too few trees were used to compute any reliable oob estimates.' ) #NEWLINE# #UNINDENT# decision = ( predictions [ k ] / predictions [ k ] . sum ( axis = 1 ) [ : , np . newaxis ] ) #NEWLINE# oob_decision_function . append ( decision ) #NEWLINE# oob_score += np . mean ( ( y [ : , k ] == np . argmax ( predictions [ k ] , axis = 1 ) ) , axis = 0 ) #NEWLINE# #UNINDENT# if ( unsampled_indices . n_outputs_ == 1 ) : #NEWLINE# #INDENT# self . oob_decision_function_ = oob_decision_function [ 0 ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . oob_decision_function_ = oob_decision_function #NEWLINE# #UNINDENT# self . oob_score_ = ( oob_score / self . n_outputs_ )