class_docstr: Abstract base class for Gradient Boosting.
class_docstr_tok: ["Abstract","base","class","for","Gradient","Boosting","."]
docstr: Fit the gradient boosting model.
  
  Parameters
  ----------
  X : {array-like, sparse matrix} of shape (n_samples, n_features)
      The input samples. Internally, it will be converted to
      ``dtype=np.float32`` and if a sparse matrix is provided
      to a sparse ``csr_matrix``.
  
  y : array-like of shape (n_samples,)
      Target values (strings or integers in classification, real numbers
      in regression)
      For classification, labels must correspond to classes.
  
  sample_weight : array-like of shape (n_samples,), default=None
      Sample weights. If None, then samples are equally weighted. Splits
      that would create child nodes with net zero or negative weight are
      ignored while searching for a split in each node. In the case of
      classification, splits are also ignored if they would result in any
      single class carrying a negative weight in either child node.
  
  monitor : callable, default=None
      The monitor is called after each iteration with the current
      iteration, a reference to the estimator and the local variables of
      ``_fit_stages`` as keyword arguments ``callable(i, self,
      locals())``. If the callable returns ``True`` the fitting procedure
      is stopped. The monitor can be used for various things such as
      computing held-out estimates, early stopping, model introspect, and
      snapshoting.
  
  Returns
  -------
  self : object
      Fitted estimator.
code: def fit(self, X, y, sample_weight=None, monitor=None):
      """Fit the gradient boosting model.
  
      Parameters
      ----------
      X : {array-like, sparse matrix} of shape (n_samples, n_features)
          The input samples. Internally, it will be converted to
          ``dtype=np.float32`` and if a sparse matrix is provided
          to a sparse ``csr_matrix``.
  
      y : array-like of shape (n_samples,)
          Target values (strings or integers in classification, real numbers
          in regression)
          For classification, labels must correspond to classes.
  
      sample_weight : array-like of shape (n_samples,), default=None
          Sample weights. If None, then samples are equally weighted. Splits
          that would create child nodes with net zero or negative weight are
          ignored while searching for a split in each node. In the case of
          classification, splits are also ignored if they would result in any
          single class carrying a negative weight in either child node.
  
      monitor : callable, default=None
          The monitor is called after each iteration with the current
          iteration, a reference to the estimator and the local variables of
          ``_fit_stages`` as keyword arguments ``callable(i, self,
          locals())``. If the callable returns ``True`` the fitting procedure
          is stopped. The monitor can be used for various things such as
          computing held-out estimates, early stopping, model introspect, and
          snapshoting.
  
      Returns
      -------
      self : object
          Fitted estimator.
      """
      if not self.warm_start:
          self._clear_state()
  
      # Check input
      # Since check_array converts both X and y to the same dtype, but the
      # trees use different types for X and y, checking them separately.
  
      X, y = self._validate_data(
          X,
          y,
          accept_sparse=["csr", "csc", "coo"],
          dtype=DTYPE,
          multi_output=True,
      )
  
      sample_weight_is_none = sample_weight is None
  
      sample_weight = _check_sample_weight(sample_weight, X)
  
      y = column_or_1d(y, warn=True)
  
      if is_classifier(self):
          y = self._validate_y(y, sample_weight)
      else:
          y = self._validate_y(y)
  
      self._check_params()
  
      if self.n_iter_no_change is not None:
          stratify = y if is_classifier(self) else None
          (
              X_train,
              X_val,
              y_train,
              y_val,
              sample_weight_train,
              sample_weight_val,
          ) = train_test_split(
              X,
              y,
              sample_weight,
              random_state=self.random_state,
              test_size=self.validation_fraction,
              stratify=stratify,
          )
          if is_classifier(self):
              if self._n_classes != np.unique(y_train).shape[0]:
                  # We choose to error here. The problem is that the init
                  # estimator would be trained on y, which has some missing
                  # classes now, so its predictions would not have the
                  # correct shape.
                  raise ValueError(
                      "The training data after the early stopping split "
                      "is missing some classes. Try using another random "
                      "seed."
                  )
      else:
          X_train, y_train, sample_weight_train = X, y, sample_weight
          X_val = y_val = sample_weight_val = None
  
      if not self._is_initialized():
          # init state
          self._init_state()
  
          # fit initial model and initialize raw predictions
          if self.init_ == "zero":
              raw_predictions = np.zeros(
                  shape=(X_train.shape[0], self._loss.K),
                  dtype=np.float64,
              )
          else:
              # XXX clean this once we have a support_sample_weight tag
              if sample_weight_is_none:
                  self.init_.fit(X_train, y_train)
              else:
                  msg = (
                      "The initial estimator {} does not support sample "
                      "weights.".format(self.init_.__class__.__name__)
                  )
                  try:
                      self.init_.fit(
                          X_train,
                          y_train,
                          sample_weight=sample_weight_train,
                      )
                  except TypeError as e:
                      if (
                          "unexpected keyword argument 'sample_weight'"
                          in str(e)
                      ):
                          # regular estimator without SW support
                          raise ValueError(msg) from e
                      else:  # regular estimator whose input checking failed
                          raise
                  except ValueError as e:
                      if (
                          "pass parameters to specific steps of "
                          "your pipeline using the "
                          "stepname__parameter" in str(e)
                      ):  # pipeline
                          raise ValueError(msg) from e
                      else:  # regular estimator whose input checking failed
                          raise
  
              raw_predictions = self._loss.get_init_raw_predictions(
                  X_train, self.init_
              )
  
          begin_at_stage = 0
  
          # The rng state must be preserved if warm_start is True
          self._rng = check_random_state(self.random_state)
  
      else:
          # add more estimators to fitted model
          # invariant: warm_start = True
          if self.n_estimators < self.estimators_.shape[0]:
              raise ValueError(
                  "n_estimators=%d must be larger or equal to "
                  "estimators_.shape[0]=%d when "
                  "warm_start==True"
                  % (self.n_estimators, self.estimators_.shape[0])
              )
          begin_at_stage = self.estimators_.shape[0]
          # The requirements of _raw_predict
          # are more constrained than fit. It accepts only CSR
          # matrices. Finite values have already been checked in _validate_data.
          X_train = check_array(
              X_train,
              dtype=DTYPE,
              order="C",
              accept_sparse="csr",
              force_all_finite=False,
          )
          raw_predictions = self._raw_predict(X_train)
          self._resize_state()
  
      # fit the boosting stages
      n_stages = self._fit_stages(
          X_train,
          y_train,
          raw_predictions,
          sample_weight_train,
          self._rng,
          X_val,
          y_val,
          sample_weight_val,
          begin_at_stage,
          monitor,
      )
  
      # change shape of arrays after fit (early-stopping or additional ests)
      if n_stages != self.estimators_.shape[0]:
          self.estimators_ = self.estimators_[:n_stages]
          self.train_score_ = self.train_score_[:n_stages]
          if hasattr(self, "oob_improvement_"):
              # OOB scores were computed
              self.oob_improvement_ = self.oob_improvement_[:n_stages]
              self.oob_scores_ = self.oob_scores_[:n_stages]
              self.oob_score_ = self.oob_scores_[-1]
      self.n_estimators_ = n_stages
      return self
  
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 10 for calling the BaseGradientBoosting obj's underlying member method code with example usage: obj.fit(X, y, sample_weight, monitor) and returns: self