class_docstr: Ridge regression with built-in Generalized Cross-Validation
  
  It allows efficient Leave-One-Out cross-validation.
  
  This class is not intended to be used directly. Use RidgeCV instead.
  
  Notes
  -----
  
  We want to solve (K + alpha*Id)c = y,
  where K = X X^T is the kernel matrix.
  
  Let G = (K + alpha*Id)^-1.
  
  Dual solution: c = Gy
  Primal solution: w = X^T c
  
  Compute eigendecomposition K = Q V Q^T.
  Then G = Q (V + alpha*Id)^-1 Q^T,
  where (V + alpha*Id) is diagonal.
  It is thus inexpensive to inverse for many alphas.
  
  Let loov be the vector of prediction values for each example
  when the model was fitted with all examples but this example.
  
  loov = (KGY - diag(KG)Y) / diag(I-KG)
  
  Let looe be the vector of prediction errors for each example
  when the model was fitted with all examples but this example.
  
  looe = y - loov = c / diag(G)
  
  References
  ----------
  http://cbcl.mit.edu/projects/cbcl/publications/ps/MIT-CSAIL-TR-2007-025.pdf
  http://www.mit.edu/~9.520/spring07/Classes/rlsslides.pdf
class_docstr_tok: ["Ridge","regression","with","built-in","Generalized","Cross-Validation","It","allows","efficient","Leave-One-Out","cross-validation",".","This","class","is","not","intended","to","be","used","directly",".","Use","RidgeCV","instead",".","Notes","--","--","-","We","want","to","solve","(","K","+","alpha","*","Id",")","c","=","y",",","where","K","=","X","X^T","is","the","kernel","matrix",".","Let","G","=","(","K","+","alpha","*","Id",")","^-1",".","Dual","solution",":","c","=","Gy","Primal","solution",":","w","=","X^T","c","Compute","eigendecomposition","K","=","Q","V","Q^T",".","Then","G","=","Q","(","V","+","alpha","*","Id",")","^-1","Q^T",",","where","(","V","+","alpha","*","Id",")","is","diagonal",".","It","is","thus","inexpensive","to","inverse","for","many","alphas",".","Let","loov","be","the","vector","of","prediction","values","for","each","example","when","the","model","was","fitted","with","all","examples","but","this","example",".","loov","=","(","KGY","-","diag","(","KG",")","Y",")","\/","diag","(","I-KG",")","Let","looe","be","the","vector","of","prediction","errors","for","each","example","when","the","model","was","fitted","with","all","examples","but","this","example",".","looe","=","y","-","loov","=","c","\/","diag","(","G",")","References","--","--","--","--","--","http",":","\/\/cbcl.mit.edu\/projects\/cbcl\/publications\/ps\/MIT-CSAIL-TR-2007-025.pdf","http",":","\/\/www.mit.edu\/~9.520\/spring07\/Classes\/rlsslides.pdf"]
docstr: Fit Ridge regression model
  
  Parameters
  ----------
  X : {array-like, sparse matrix}, shape = [n_samples, n_features]
      Training data
  
  y : array-like, shape = [n_samples] or [n_samples, n_targets]
      Target values
  
  sample_weight : float or array-like of shape [n_samples]
      Sample weight
  
  Returns
  -------
  self : Returns self.
docstr_tok: ["Fit","Ridge","regression","model","Parameters","--","--","--","--","--","X",":","{","array-like",",","sparse","matrix","}",",","shape","=","[","n_samples",",","n_features","]","Training","data","y",":","array-like",",","shape","=","[","n_samples","]","or","[","n_samples",",","n_targets","]","Target","values","sample_weight",":","float","or","array-like","of","shape","[","n_samples","]","Sample","weight","Returns","--","--","--","-","self",":","Returns","self","."]
code: def fit(self, X, y, sample_weight=None):
      """Fit Ridge regression model
  
      Parameters
      ----------
      X : {array-like, sparse matrix}, shape = [n_samples, n_features]
          Training data
  
      y : array-like, shape = [n_samples] or [n_samples, n_targets]
          Target values
  
      sample_weight : float or array-like of shape [n_samples]
          Sample weight
  
      Returns
      -------
      self : Returns self.
      """
      X, y = check_X_y(
          X,
          y,
          ["csr", "csc", "coo"],
          dtype=np.float64,
          multi_output=True,
          y_numeric=True,
      )
      n_samples, n_features = X.shape
  
      X, y, X_offset, y_offset, X_scale = LinearModel._preprocess_data(
          X,
          y,
          self.fit_intercept,
          self.normalize,
          self.copy_X,
          sample_weight=sample_weight,
      )
  
      gcv_mode = self.gcv_mode
      with_sw = len(np.shape(sample_weight))
  
      if gcv_mode is None or gcv_mode == "auto":
          if sparse.issparse(X) or n_features > n_samples or with_sw:
              gcv_mode = "eigen"
          else:
              gcv_mode = "svd"
      elif gcv_mode == "svd" and with_sw:
          # FIXME non-uniform sample weights not yet supported
          warnings.warn(
              "non-uniform sample weights unsupported for svd, "
              "forcing usage of eigen"
          )
          gcv_mode = "eigen"
  
      if gcv_mode == "eigen":
          _pre_compute = self._pre_compute
          _errors = self._errors
          _values = self._values
      elif gcv_mode == "svd":
          # assert n_samples >= n_features
          _pre_compute = self._pre_compute_svd
          _errors = self._errors_svd
          _values = self._values_svd
      else:
          raise ValueError('bad gcv_mode "%s"' % gcv_mode)
  
      if sample_weight is not None:
          X, y = _rescale_data(X, y, sample_weight)
  
      centered_kernel = not sparse.issparse(X) and self.fit_intercept
  
      v, Q, QT_y = _pre_compute(X, y, centered_kernel)
      n_y = 1 if len(y.shape) == 1 else y.shape[1]
      cv_values = np.zeros((n_samples * n_y, len(self.alphas)))
      C = []
  
      scorer = check_scoring(
          self, scoring=self.scoring, allow_none=True
      )
      error = scorer is None
  
      for i, alpha in enumerate(self.alphas):
          if error:
              out, c = _errors(alpha, y, v, Q, QT_y)
          else:
              out, c = _values(alpha, y, v, Q, QT_y)
          cv_values[:, i] = out.ravel()
          C.append(c)
  
      if error:
          best = cv_values.mean(axis=0).argmin()
      else:
          # The scorer want an object that will make the predictions but
          # they are already computed efficiently by _RidgeGCV. This
          # identity_estimator will just return them
          def identity_estimator():
              pass
  
          identity_estimator.decision_function = (
              lambda y_predict: y_predict
          )
          identity_estimator.predict = lambda y_predict: y_predict
  
          out = [
              scorer(identity_estimator, y.ravel(), cv_values[:, i])
              for i in range(len(self.alphas))
          ]
          best = np.argmax(out)
  
      self.alpha_ = self.alphas[best]
      self.dual_coef_ = C[best]
      self.coef_ = safe_sparse_dot(self.dual_coef_.T, X)
  
      self._set_intercept(X_offset, y_offset, X_scale)
  
      if self.store_cv_values:
          if len(y.shape) == 1:
              cv_values_shape = n_samples, len(self.alphas)
          else:
              cv_values_shape = n_samples, n_y, len(self.alphas)
          self.cv_values_ = cv_values.reshape(cv_values_shape)
  
      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 12 for calling the _RidgeGCV obj's underlying member method code with example usage: obj.fit(X, y, sample_weight) and returns: self