code: def fit(self, X, y, sample_weight=None):
      X, y = check_X_y(
          X,
          y,
          ["csr", "csc", "coo"],
          dtype=np.float64,
          multi_output=True,
          y_numeric=True,
      )
  
      if (sample_weight is not None) and np.atleast_1d(
          sample_weight
      ).ndim > 1:
          raise ValueError("Sample weights must be 1D array or scalar")
  
      X, y, X_offset, y_offset, X_scale = self._preprocess_data(
          X,
          y,
          self.fit_intercept,
          self.normalize,
          self.copy_X,
          sample_weight=sample_weight,
      )
  
      # temporary fix for fitting the intercept with sparse data using 'sag'
      if sparse.issparse(X) and self.fit_intercept:
          self.coef_, self.n_iter_, self.intercept_ = ridge_regression(
              X,
              y,
              alpha=self.alpha,
              sample_weight=sample_weight,
              max_iter=self.max_iter,
              tol=self.tol,
              solver=self.solver,
              random_state=self.random_state,
              return_n_iter=True,
              return_intercept=True,
          )
          self.intercept_ += y_offset
      else:
          self.coef_, self.n_iter_ = ridge_regression(
              X,
              y,
              alpha=self.alpha,
              sample_weight=sample_weight,
              max_iter=self.max_iter,
              tol=self.tol,
              solver=self.solver,
              random_state=self.random_state,
              return_n_iter=True,
              return_intercept=False,
          )
          self._set_intercept(X_offset, y_offset, X_scale)
  
      return self
  
imports: from abc import ABCMeta, abstractmethod
  import warnings
  import numpy
  from scipy import linalg
  from scipy import sparse
  from scipy.sparse import linalg
  from .base import LinearClassifierMixin, LinearModel, _rescale_data
  from .sag import sag_solver
  from ..base import RegressorMixin
  from ..utils.extmath import safe_sparse_dot
  from ..utils.extmath import row_norms
  from ..utils import check_X_y
  from ..utils import check_array
  from ..utils import check_consistent_length
  from ..utils import compute_sample_weight
  from ..utils import column_or_1d
  from ..preprocessing import LabelBinarizer
  from ..model_selection import GridSearchCV
  from ..externals import six
  from ..metrics.scorer import check_scoring
label_desc: Use image node_id 2 for calling the _BaseRidge obj's underlying member method code with example usage: obj.fit(X, y, sample_weight) and returns: self