class_docstr: Bayesian ridge regression.
  
  Fit a Bayesian ridge model. See the Notes section for details on this
  implementation and the optimization of the regularization parameters
  lambda (precision of the weights) and alpha (precision of the noise).
  
  Read more in the :ref:`User Guide <bayesian_regression>`.
  
  Parameters
  ----------
  max_iter : int, default=None
      Maximum number of iterations over the complete dataset before
      stopping independently of any early stopping criterion. If `None`, it
      corresponds to `max_iter=300`.
  
      .. versionchanged:: 1.3
  
  tol : float, default=1e-3
      Stop the algorithm if w has converged.
  
  alpha_1 : float, default=1e-6
      Hyper-parameter : shape parameter for the Gamma distribution prior
      over the alpha parameter.
  
  alpha_2 : float, default=1e-6
      Hyper-parameter : inverse scale parameter (rate parameter) for the
      Gamma distribution prior over the alpha parameter.
  
  lambda_1 : float, default=1e-6
      Hyper-parameter : shape parameter for the Gamma distribution prior
      over the lambda parameter.
  
  lambda_2 : float, default=1e-6
      Hyper-parameter : inverse scale parameter (rate parameter) for the
      Gamma distribution prior over the lambda parameter.
  
  alpha_init : float, default=None
      Initial value for alpha (precision of the noise).
      If not set, alpha_init is 1/Var(y).
  
          .. versionadded:: 0.22
  
  lambda_init : float, default=None
      Initial value for lambda (precision of the weights).
      If not set, lambda_init is 1.
  
          .. versionadded:: 0.22
  
  compute_score : bool, default=False
      If True, compute the log marginal likelihood at each iteration of the
      optimization.
  
  fit_intercept : bool, default=True
      Whether to calculate the intercept for this model.
      The intercept is not treated as a probabilistic parameter
      and thus has no associated variance. If set
      to False, no intercept will be used in calculations
      (i.e. data is expected to be centered).
  
  copy_X : bool, default=True
      If True, X will be copied; else, it may be overwritten.
  
  verbose : bool, default=False
      Verbose mode when fitting the model.
  
  n_iter : int
      Maximum number of iterations. Should be greater than or equal to 1.
  
      .. deprecated:: 1.3
         `n_iter` is deprecated in 1.3 and will be removed in 1.5. Use
         `max_iter` instead.
  
  Attributes
  ----------
  coef_ : array-like of shape (n_features,)
      Coefficients of the regression model (mean of distribution)
  
  intercept_ : float
      Independent term in decision function. Set to 0.0 if
      `fit_intercept = False`.
  
  alpha_ : float
     Estimated precision of the noise.
  
  lambda_ : float
     Estimated precision of the weights.
  
  sigma_ : array-like of shape (n_features, n_features)
      Estimated variance-covariance matrix of the weights
  
  scores_ : array-like of shape (n_iter_+1,)
      If computed_score is True, value of the log marginal likelihood (to be
      maximized) at each iteration of the optimization. The array starts
      with the value of the log marginal likelihood obtained for the initial
      values of alpha and lambda and ends with the value obtained for the
      estimated alpha and lambda.
  
  n_iter_ : int
      The actual number of iterations to reach the stopping criterion.
  
  X_offset_ : ndarray of shape (n_features,)
      If `fit_intercept=True`, offset subtracted for centering data to a
      zero mean. Set to np.zeros(n_features) otherwise.
  
  X_scale_ : ndarray of shape (n_features,)
      Set to np.ones(n_features).
  
  n_features_in_ : int
      Number of features seen during :term:`fit`.
  
      .. versionadded:: 0.24
  
  feature_names_in_ : ndarray of shape (`n_features_in_`,)
      Names of features seen during :term:`fit`. Defined only when `X`
      has feature names that are all strings.
  
      .. versionadded:: 1.0
  
  See Also
  --------
  ARDRegression : Bayesian ARD regression.
  
  Notes
  -----
  There exist several strategies to perform Bayesian ridge regression. This
  implementation is based on the algorithm described in Appendix A of
  (Tipping, 2001) where updates of the regularization parameters are done as
  suggested in (MacKay, 1992). Note that according to A New
  View of Automatic Relevance Determination (Wipf and Nagarajan, 2008) these
  update rules do not guarantee that the marginal likelihood is increasing
  between two consecutive iterations of the optimization.
  
  References
  ----------
  D. J. C. MacKay, Bayesian Interpolation, Computation and Neural Systems,
  Vol. 4, No. 3, 1992.
  
  M. E. Tipping, Sparse Bayesian Learning and the Relevance Vector Machine,
  Journal of Machine Learning Research, Vol. 1, 2001.
  
  Examples
  --------
  >>> from sklearn import linear_model
  >>> clf = linear_model.BayesianRidge()
  >>> clf.fit([[0,0], [1, 1], [2, 2]], [0, 1, 2])
  BayesianRidge()
  >>> clf.predict([[1, 1]])
  array([1.])
class_docstr_tok: ["Bayesian","ridge","regression",".","Fit","a","Bayesian","ridge","model",".","See","the","Notes","section","for","details","on","this","implementation","and","the","optimization","of","the","regularization","parameters","lambda","(","precision","of","the","weights",")","and","alpha","(","precision","of","the","noise",")",".","Read","more","in","the",":","ref",":","`","User","Guide","<","bayesian_regression",">","`",".","Parameters","--","--","--","--","--","max_iter",":","int",",","default=None","Maximum","number","of","iterations","over","the","complete","dataset","before","stopping","independently","of","any","early","stopping","criterion",".","If","`","None","`",",","it","corresponds","to","`","max_iter=300","`",".","..","versionchanged",":",":","1.3","tol",":","float",",","default=1e-3","Stop","the","algorithm","if","w","has","converged",".","alpha_1",":","float",",","default=1e-6","Hyper-parameter",":","shape","parameter","for","the","Gamma","distribution","prior","over","the","alpha","parameter",".","alpha_2",":","float",",","default=1e-6","Hyper-parameter",":","inverse","scale","parameter","(","rate","parameter",")","for","the","Gamma","distribution","prior","over","the","alpha","parameter",".","lambda_1",":","float",",","default=1e-6","Hyper-parameter",":","shape","parameter","for","the","Gamma","distribution","prior","over","the","lambda","parameter",".","lambda_2",":","float",",","default=1e-6","Hyper-parameter",":","inverse","scale","parameter","(","rate","parameter",")","for","the","Gamma","distribution","prior","over","the","lambda","parameter",".","alpha_init",":","float",",","default=None","Initial","value","for","alpha","(","precision","of","the","noise",")",".","If","not","set",",","alpha_init","is","1\/Var","(","y",")",".","..","versionadded",":",":","0.22","lambda_init",":","float",",","default=None","Initial","value","for","lambda","(","precision","of","the","weights",")",".","If","not","set",",","lambda_init","is","1",".","..","versionadded",":",":","0.22","compute_score",":","bool",",","default=False","If","True",",","compute","the","log","marginal","likelihood","at","each","iteration","of","the","optimization",".","fit_intercept",":","bool",",","default=True","Whether","to","calculate","the","intercept","for","this","model",".","The","intercept","is","not","treated","as","a","probabilistic","parameter","and","thus","has","no","associated","variance",".","If","set","to","False",",","no","intercept","will","be","used","in","calculations","(","i.e",".","data","is","expected","to","be","centered",")",".","copy_X",":","bool",",","default=True","If","True",",","X","will","be","copied",";","else",",","it","may","be","overwritten",".","verbose",":","bool",",","default=False","Verbose","mode","when","fitting","the","model",".","n_iter",":","int","Maximum","number","of","iterations",".","Should","be","greater","than","or","equal","to","1",".","..","deprecated",":",":","1.3","`","n_iter","`","is","deprecated","in","1.3","and","will","be","removed","in","1.5",".","Use","`","max_iter","`","instead",".","Attributes","--","--","--","--","--","coef_",":","array-like","of","shape","(","n_features",",",")","Coefficients","of","the","regression","model","(","mean","of","distribution",")","intercept_",":","float","Independent","term","in","decision","function",".","Set","to","0.0","if","`","fit_intercept","=","False","`",".","alpha_",":","float","Estimated","precision","of","the","noise",".","lambda_",":","float","Estimated","precision","of","the","weights",".","sigma_",":","array-like","of","shape","(","n_features",",","n_features",")","Estimated","variance-covariance","matrix","of","the","weights","scores_",":","array-like","of","shape","(","n_iter_+1",",",")","If","computed_score","is","True",",","value","of","the","log","marginal","likelihood","(","to","be","maximized",")","at","each","iteration","of","the","optimization",".","The","array","starts","with","the","value","of","the","log","marginal","likelihood","obtained","for","the","initial","values","of","alpha","and","lambda","and","ends","with","the","value","obtained","for","the","estimated","alpha","and","lambda",".","n_iter_",":","int","The","actual","number","of","iterations","to","reach","the","stopping","criterion",".","X_offset_",":","ndarray","of","shape","(","n_features",",",")","If","`","fit_intercept=True","`",",","offset","subtracted","for","centering","data","to","a","zero","mean",".","Set","to","np.zeros","(","n_features",")","otherwise",".","X_scale_",":","ndarray","of","shape","(","n_features",",",")","Set","to","np.ones","(","n_features",")",".","n_features_in_",":","int","Number","of","features","seen","during",":","term",":","`","fit","`",".","..","versionadded",":",":","0.24","feature_names_in_",":","ndarray","of","shape","(","`","n_features_in_","`",",",")","Names","of","features","seen","during",":","term",":","`","fit","`",".","Defined","only","when","`","X","`","has","feature","names","that","are","all","strings",".","..","versionadded",":",":","1.0","See","Also","--","--","--","--","ARDRegression",":","Bayesian","ARD","regression",".","Notes","--","--","-","There","exist","several","strategies","to","perform","Bayesian","ridge","regression",".","This","implementation","is","based","on","the","algorithm","described","in","Appendix","A","of","(","Tipping",",","2001",")","where","updates","of","the","regularization","parameters","are","done","as","suggested","in","(","MacKay",",","1992",")",".","Note","that","according","to","A","New","View","of","Automatic","Relevance","Determination","(","Wipf","and","Nagarajan",",","2008",")","these","update","rules","do","not","guarantee","that","the","marginal","likelihood","is","increasing","between","two","consecutive","iterations","of","the","optimization",".","References","--","--","--","--","--","D.","J.","C.","MacKay",",","Bayesian","Interpolation",",","Computation","and","Neural","Systems",",","Vol",".","4",",","No",".","3",",","1992",".","M.","E.","Tipping",",","Sparse","Bayesian","Learning","and","the","Relevance","Vector","Machine",",","Journal","of","Machine","Learning","Research",",","Vol",".","1",",","2001",".","Examples","--","--","--","--",">",">",">","from","sklearn","import","linear_model",">",">",">","clf","=","linear_model.BayesianRidge","(",")",">",">",">","clf.fit","(","[","[","0,0","]",",","[","1",",","1","]",",","[","2",",","2","]","]",",","[","0",",","1",",","2","]",")","BayesianRidge","(",")",">",">",">","clf.predict","(","[","[","1",",","1","]","]",")","array","(","[","1",".","]",")"]
docstr: Fit the model.
  
  Parameters
  ----------
  X : ndarray of shape (n_samples, n_features)
      Training data.
  y : ndarray of shape (n_samples,)
      Target values. Will be cast to X's dtype if necessary.
  
  sample_weight : ndarray of shape (n_samples,), default=None
      Individual weights for each sample.
  
      .. versionadded:: 0.20
         parameter *sample_weight* support to BayesianRidge.
  
  Returns
  -------
  self : object
      Returns the instance itself.
docstr_tok: ["Fit","the","model",".","Parameters","--","--","--","--","--","X",":","ndarray","of","shape","(","n_samples",",","n_features",")","Training","data",".","y",":","ndarray","of","shape","(","n_samples",",",")","Target","values",".","Will","be","cast","to","X","'s","dtype","if","necessary",".","sample_weight",":","ndarray","of","shape","(","n_samples",",",")",",","default=None","Individual","weights","for","each","sample",".","..","versionadded",":",":","0.20","parameter","*","sample_weight","*","support","to","BayesianRidge",".","Returns","--","--","--","-","self",":","object","Returns","the","instance","itself","."]
code: def fit(self, X, y, sample_weight=None):
      """Fit the model.
  
      Parameters
      ----------
      X : ndarray of shape (n_samples, n_features)
          Training data.
      y : ndarray of shape (n_samples,)
          Target values. Will be cast to X's dtype if necessary.
  
      sample_weight : ndarray of shape (n_samples,), default=None
          Individual weights for each sample.
  
          .. versionadded:: 0.20
             parameter *sample_weight* support to BayesianRidge.
  
      Returns
      -------
      self : object
          Returns the instance itself.
      """
      max_iter = _deprecate_n_iter(self.n_iter, self.max_iter)
  
      X, y = self._validate_data(
          X, y, dtype=[np.float64, np.float32], y_numeric=True
      )
      dtype = X.dtype
  
      if sample_weight is not None:
          sample_weight = _check_sample_weight(
              sample_weight, X, dtype=dtype
          )
  
      X, y, X_offset_, y_offset_, X_scale_ = _preprocess_data(
          X,
          y,
          fit_intercept=self.fit_intercept,
          copy=self.copy_X,
          sample_weight=sample_weight,
      )
  
      if sample_weight is not None:
          # Sample weight can be implemented via a simple rescaling.
          X, y, _ = _rescale_data(X, y, sample_weight)
  
      self.X_offset_ = X_offset_
      self.X_scale_ = X_scale_
      n_samples, n_features = X.shape
  
      # Initialization of the values of the parameters
      eps = np.finfo(np.float64).eps
      # Add `eps` in the denominator to omit division by zero if `np.var(y)`
      # is zero
      alpha_ = self.alpha_init
      lambda_ = self.lambda_init
      if alpha_ is None:
          alpha_ = 1.0 / (np.var(y) + eps)
      if lambda_ is None:
          lambda_ = 1.0
  
      # Avoid unintended type promotion to float64 with numpy 2
      alpha_ = np.asarray(alpha_, dtype=dtype)
      lambda_ = np.asarray(lambda_, dtype=dtype)
  
      verbose = self.verbose
      lambda_1 = self.lambda_1
      lambda_2 = self.lambda_2
      alpha_1 = self.alpha_1
      alpha_2 = self.alpha_2
  
      self.scores_ = list()
      coef_old_ = None
  
      XT_y = np.dot(X.T, y)
      U, S, Vh = linalg.svd(X, full_matrices=False)
      eigen_vals_ = S**2
  
      # Convergence loop of the bayesian ridge regression
      for iter_ in range(max_iter):
          # update posterior mean coef_ based on alpha_ and lambda_ and
          # compute corresponding rmse
          coef_, rmse_ = self._update_coef_(
              X,
              y,
              n_samples,
              n_features,
              XT_y,
              U,
              Vh,
              eigen_vals_,
              alpha_,
              lambda_,
          )
          if self.compute_score:
              # compute the log marginal likelihood
              s = self._log_marginal_likelihood(
                  n_samples,
                  n_features,
                  eigen_vals_,
                  alpha_,
                  lambda_,
                  coef_,
                  rmse_,
              )
              self.scores_.append(s)
  
          # Update alpha and lambda according to (MacKay, 1992)
          gamma_ = np.sum(
              (alpha_ * eigen_vals_) / (lambda_ + alpha_ * eigen_vals_)
          )
          lambda_ = (gamma_ + 2 * lambda_1) / (
              np.sum(coef_**2) + 2 * lambda_2
          )
          alpha_ = (n_samples - gamma_ + 2 * alpha_1) / (
              rmse_ + 2 * alpha_2
          )
  
          # Check for convergence
          if (
              iter_ != 0
              and np.sum(np.abs(coef_old_ - coef_)) < self.tol
          ):
              if verbose:
                  print("Convergence after ", str(iter_), " iterations")
              break
          coef_old_ = np.copy(coef_)
  
      self.n_iter_ = iter_ + 1
  
      # return regularization parameters and corresponding posterior mean,
      # log marginal likelihood and posterior covariance
      self.alpha_ = alpha_
      self.lambda_ = lambda_
      self.coef_, rmse_ = self._update_coef_(
          X,
          y,
          n_samples,
          n_features,
          XT_y,
          U,
          Vh,
          eigen_vals_,
          alpha_,
          lambda_,
      )
      if self.compute_score:
          # compute the log marginal likelihood
          s = self._log_marginal_likelihood(
              n_samples,
              n_features,
              eigen_vals_,
              alpha_,
              lambda_,
              coef_,
              rmse_,
          )
          self.scores_.append(s)
          self.scores_ = np.array(self.scores_)
  
      # posterior covariance is given by 1/alpha_ * scaled_sigma_
      scaled_sigma_ = np.dot(
          Vh.T, Vh / (eigen_vals_ + lambda_ / alpha_)[:, np.newaxis]
      )
      self.sigma_ = (1.0 / alpha_) * scaled_sigma_
  
      self._set_intercept(X_offset_, y_offset_, X_scale_)
  
      return self
  
imports: import warnings
  from math import log
  from numbers import Integral, Real
  import numpy
  from scipy import linalg
  from scipy.linalg import pinvh
  from ..base import RegressorMixin, _fit_context
  from ..utils._param_validation import Hidden, Interval, StrOptions
  from ..utils.extmath import fast_logdet
  from ..utils.validation import _check_sample_weight
  from ._base import LinearModel, _preprocess_data, _rescale_data
label_desc: Use image node_id 2 for calling the BayesianRidge obj's underlying member method code with example usage: obj.fit(X, y, sample_weight) and returns: self