original_docstring: Compute out-of-bag score
docstring: Compute out-of-bag score
docstring_tokens: Compute out - of - bag score
code: def _set_oob_score(self, X, y):
          """Compute out-of-bag score"""
          X = check_array(X, dtype=DTYPE, accept_sparse='csr')
          if self.n_classes_[0] > 2:
              n_classes_ = list(
                  np.asarray(
                      self.n_classes_) -
                  1)  # CHANGED TO K-1
          else:
              n_classes_ = self.n_classes_
          n_samples = y.shape[0]
  
          n_samples_bootstrap = _get_n_samples_bootstrap(
              n_samples, self.max_samples
          )
          
          oob_decision_function = []
          oob_score = 0.0
          predictions = []
              
          for k in range(self.n_outputs_):
              predictions.append(np.zeros((n_samples, n_classes_[k])))
  
          for estimator in self.estimators_:
              unsampled_indices = _generate_unsampled_indices(
                  estimator.random_state, n_samples, n_samples_bootstrap)
              p_estimator = estimator.predict_cum_proba(X[unsampled_indices, :],
                                                    check_input=False)
  
              if self.n_outputs_ == 1:
                  p_estimator = [p_estimator]
  
              for k in range(self.n_outputs_):
                  predictions[k][unsampled_indices, :] += p_estimator[k]
  
          for k in range(self.n_outputs_):
              if (predictions[k].sum(axis=1) == 0).any():
                  warn("Some inputs do not have OOB scores. "
                       "This probably means too few trees were used "
                       "to compute any reliable oob estimates.")
  
              decision = (predictions[k] /
                          predictions[k].sum(axis=1)[:, np.newaxis])
              oob_decision_function.append(decision)
              if self.n_classes_[0] <= 2:
                  oob_score += np.mean(y[:, k] ==
                                       np.argmax(predictions[k], axis=1), axis=0)
              else:
                  class_index = np.sum(
                      (predictions[k] > 0.5).astype(
                          np.int), axis=1)
                  oob_score += np.mean(y[:, k] == class_index, axis=0)
  
          if self.n_outputs_ == 1:
              self.oob_decision_function_ = oob_decision_function[0]
          else:
              self.oob_decision_function_ = oob_decision_function
  
          self.oob_score_ = oob_score / self.n_outputs_
code_tokens: def _set_oob_score ( self , X , y ) : X = check_array ( X , dtype = DTYPE , accept_sparse = 'csr' ) if self . n_classes_ [ 0 ] > 2 : n_classes_ = list ( np . asarray ( self . n_classes_ ) - 1 ) else : n_classes_ = self . n_classes_ n_samples = y . shape [ 0 ] n_samples_bootstrap = _get_n_samples_bootstrap ( n_samples , self . max_samples ) oob_decision_function = [ ] oob_score = 0.0 predictions = [ ] for k in range ( self . n_outputs_ ) : predictions . append ( np . zeros ( ( n_samples , n_classes_ [ k ] ) ) ) for estimator in self . estimators_ : unsampled_indices = _generate_unsampled_indices ( estimator . random_state , n_samples , n_samples_bootstrap ) p_estimator = estimator . predict_cum_proba ( X [ unsampled_indices , : ] , check_input = False ) if self . n_outputs_ == 1 : p_estimator = [ p_estimator ] for k in range ( self . n_outputs_ ) : predictions [ k ] [ unsampled_indices , : ] += p_estimator [ k ] for k in range ( self . n_outputs_ ) : if ( predictions [ k ] . sum ( axis = 1 ) == 0 ) . any ( ) : warn ( "Some inputs do not have OOB scores. " "This probably means too few trees were used " "to compute any reliable oob estimates." ) decision = ( predictions [ k ] / predictions [ k ] . sum ( axis = 1 ) [ : , np . newaxis ] ) oob_decision_function . append ( decision ) if self . n_classes_ [ 0 ] <= 2 : oob_score += np . mean ( y [ : , k ] == np . argmax ( predictions [ k ] , axis = 1 ) , axis = 0 ) else : class_index = np . sum ( ( predictions [ k ] > 0.5 ) . astype ( np . int ) , axis = 1 ) oob_score += np . mean ( y [ : , k ] == class_index , axis = 0 ) if self . n_outputs_ == 1 : self . oob_decision_function_ = oob_decision_function [ 0 ] else : self . oob_decision_function_ = oob_decision_function self . oob_score_ = oob_score / self . n_outputs_
short_docstring: Compute out-of-bag score
short_docstring_tokens: Compute out - of - bag score
comment: """Compute out-of-bag score"""$SEP$# CHANGED TO K-1