class_docstr: Abstract base class for Gradient Boosting.
class_docstr_tok: ["Abstract","base","class","for","Gradient","Boosting","."]
docstr: Iteratively fits the stages.
  
  For each stage it computes the progress (OOB, train score)
  and delegates to ``_fit_stage``.
  Returns the number of stages fit; might differ from ``n_estimators``
  due to early stopping.
code: def _fit_stages(
      self,
      X,
      y,
      raw_predictions,
      sample_weight,
      random_state,
      X_val,
      y_val,
      sample_weight_val,
      begin_at_stage=0,
      monitor=None,
  ):
      """Iteratively fits the stages.
  
      For each stage it computes the progress (OOB, train score)
      and delegates to ``_fit_stage``.
      Returns the number of stages fit; might differ from ``n_estimators``
      due to early stopping.
      """
      n_samples = X.shape[0]
      do_oob = self.subsample < 1.0
      sample_mask = np.ones((n_samples,), dtype=bool)
      n_inbag = max(1, int(self.subsample * n_samples))
      loss_ = self._loss
  
      if self.verbose:
          verbose_reporter = VerboseReporter(verbose=self.verbose)
          verbose_reporter.init(self, begin_at_stage)
  
      X_csc = csc_matrix(X) if issparse(X) else None
      X_csr = csr_matrix(X) if issparse(X) else None
  
      if self.n_iter_no_change is not None:
          loss_history = np.full(self.n_iter_no_change, np.inf)
          # We create a generator to get the predictions for X_val after
          # the addition of each successive stage
          y_val_pred_iter = self._staged_raw_predict(
              X_val, check_input=False
          )
  
      # perform boosting iterations
      i = begin_at_stage
      for i in range(begin_at_stage, self.n_estimators):
          # subsampling
          if do_oob:
              sample_mask = _random_sample_mask(
                  n_samples, n_inbag, random_state
              )
              if (
                  i == 0
              ):  # store the initial loss to compute the OOB score
                  initial_loss = loss_(
                      y[~sample_mask],
                      raw_predictions[~sample_mask],
                      sample_weight[~sample_mask],
                  )
  
          # fit next stage of trees
          raw_predictions = self._fit_stage(
              i,
              X,
              y,
              raw_predictions,
              sample_weight,
              sample_mask,
              random_state,
              X_csc,
              X_csr,
          )
  
          # track loss
          if do_oob:
              self.train_score_[i] = loss_(
                  y[sample_mask],
                  raw_predictions[sample_mask],
                  sample_weight[sample_mask],
              )
              self.oob_scores_[i] = loss_(
                  y[~sample_mask],
                  raw_predictions[~sample_mask],
                  sample_weight[~sample_mask],
              )
              previous_loss = (
                  initial_loss if i == 0 else self.oob_scores_[i - 1]
              )
              self.oob_improvement_[i] = (
                  previous_loss - self.oob_scores_[i]
              )
              self.oob_score_ = self.oob_scores_[-1]
          else:
              # no need to fancy index w/ no subsampling
              self.train_score_[i] = loss_(
                  y, raw_predictions, sample_weight
              )
  
          if self.verbose > 0:
              verbose_reporter.update(i, self)
  
          if monitor is not None:
              early_stopping = monitor(i, self, locals())
              if early_stopping:
                  break
  
          # We also provide an early stopping based on the score from
          # validation set (X_val, y_val), if n_iter_no_change is set
          if self.n_iter_no_change is not None:
              # By calling next(y_val_pred_iter), we get the predictions
              # for X_val after the addition of the current stage
              validation_loss = loss_(
                  y_val, next(y_val_pred_iter), sample_weight_val
              )
  
              # Require validation_score to be better (less) than at least
              # one of the last n_iter_no_change evaluations
              if np.any(validation_loss + self.tol < loss_history):
                  loss_history[i % len(loss_history)] = validation_loss
              else:
                  break
  
      return i + 1
  
imports: import warnings
  from abc import ABCMeta, abstractmethod
  from numbers import Integral, Real
  from time import time
  import numpy
  from scipy.sparse import csc_matrix, csr_matrix, issparse
  from ..base import ClassifierMixin, RegressorMixin, _fit_context, is_classifier
  from ..exceptions import NotFittedError
  from ..model_selection import train_test_split
  from ..tree import DecisionTreeRegressor
  from ..tree._tree import DOUBLE, DTYPE
  from ..utils import check_array, check_random_state, column_or_1d
  from ..utils._param_validation import HasMethods, Interval, StrOptions
  from ..utils.multiclass import check_classification_targets
  from ..utils.validation import _check_sample_weight, check_is_fitted
  from .None import _gb_losses
  from ._base import BaseEnsemble
  from ._gradient_boosting import _random_sample_mask, predict_stage, predict_stages
label_desc: Use image node_id 11 for calling the BaseGradientBoosting obj's underlying member method code with example usage: obj._fit_stages(X, y, raw_predictions, sample_weight, random_state, X_val, y_val, sample_weight_val, begin_at_stage, monitor) and returns: unknown