parameters: (self, X, y, sample_weight=None)
return_statement: return self
docstring: Fit linear model.
  
          Parameters
          ----------
          X : {array-like, sparse matrix} of shape (n_samples, n_features)
              Training data
  
          y : array-like of shape (n_samples,) or (n_samples, n_targets)
              Target values. Will be cast to X's dtype if necessary
  
          sample_weight : array-like of shape (n_samples,), default=None
              Individual weights for each sample
  
              .. versionadded:: 0.17
                 parameter *sample_weight* support to LinearRegression.
  
          Returns
          -------
          self : returns an instance of self.
docstring_summary: Fit linear model.
docstring_tokens: Fit linear model .
function: def fit(self, X, y, sample_weight=None):
          """
          Fit linear model.
  
          Parameters
          ----------
          X : {array-like, sparse matrix} of shape (n_samples, n_features)
              Training data
  
          y : array-like of shape (n_samples,) or (n_samples, n_targets)
              Target values. Will be cast to X's dtype if necessary
  
          sample_weight : array-like of shape (n_samples,), default=None
              Individual weights for each sample
  
              .. versionadded:: 0.17
                 parameter *sample_weight* support to LinearRegression.
  
          Returns
          -------
          self : returns an instance of self.
          """
  
          n_jobs_ = self.n_jobs
          X, y = check_X_y(X, y, accept_sparse=['csr', 'csc', 'coo'],
                           y_numeric=True, multi_output=True)
  
          if sample_weight is not None:
              sample_weight = _check_sample_weight(sample_weight, X,
                                                   dtype=X.dtype)
  
          X, y, X_offset, y_offset, X_scale = self._preprocess_data(
              X, y, fit_intercept=self.fit_intercept, normalize=self.normalize,
              copy=self.copy_X, sample_weight=sample_weight,
              return_mean=True)
  
          if sample_weight is not None:
              # Sample weight can be implemented via a simple rescaling.
              X, y = _rescale_data(X, y, sample_weight)
  
          if sp.issparse(X):
              X_offset_scale = X_offset / X_scale
  
              def matvec(b):
                  return X.dot(b) - b.dot(X_offset_scale)
  
              def rmatvec(b):
                  return X.T.dot(b) - X_offset_scale * np.sum(b)
  
              X_centered = sparse.linalg.LinearOperator(shape=X.shape,
                                                        matvec=matvec,
                                                        rmatvec=rmatvec)
  
              if y.ndim < 2:
                  out = sparse_lsqr(X_centered, y)
                  self.coef_ = out[0]
                  self._residues = out[3]
              else:
                  # sparse_lstsq cannot handle y with shape (M, K)
                  outs = Parallel(n_jobs=n_jobs_)(
                      delayed(sparse_lsqr)(X_centered, y[:, j].ravel())
                      for j in range(y.shape[1]))
                  self.coef_ = np.vstack([out[0] for out in outs])
                  self._residues = np.vstack([out[3] for out in outs])
          else:
              self.coef_, self._residues, self.rank_, self.singular_ = \
                  linalg.lstsq(X, y)
              self.coef_ = self.coef_.T
  
          if y.ndim == 1:
              self.coef_ = np.ravel(self.coef_)
          self._set_intercept(X_offset, y_offset, X_scale)
          return self
function_tokens: def fit ( self , X , y , sample_weight = None ) : n_jobs_ = self . n_jobs X , y = check_X_y ( X , y , accept_sparse = [ 'csr' , 'csc' , 'coo' ] , y_numeric = True , multi_output = True ) if sample_weight is not None : sample_weight = _check_sample_weight ( sample_weight , X , dtype = X . dtype ) X , y , X_offset , y_offset , X_scale = self . _preprocess_data ( X , y , fit_intercept = self . fit_intercept , normalize = self . normalize , copy = self . copy_X , sample_weight = sample_weight , return_mean = True ) if sample_weight is not None : # Sample weight can be implemented via a simple rescaling. X , y = _rescale_data ( X , y , sample_weight ) if sp . issparse ( X ) : X_offset_scale = X_offset / X_scale def matvec ( b ) : return X . dot ( b ) - b . dot ( X_offset_scale ) def rmatvec ( b ) : return X . T . dot ( b ) - X_offset_scale * np . sum ( b ) X_centered = sparse . linalg . LinearOperator ( shape = X . shape , matvec = matvec , rmatvec = rmatvec ) if y . ndim < 2 : out = sparse_lsqr ( X_centered , y ) self . coef_ = out [ 0 ] self . _residues = out [ 3 ] else : # sparse_lstsq cannot handle y with shape (M, K) outs = Parallel ( n_jobs = n_jobs_ ) ( delayed ( sparse_lsqr ) ( X_centered , y [ : , j ] . ravel ( ) ) for j in range ( y . shape [ 1 ] ) ) self . coef_ = np . vstack ( [ out [ 0 ] for out in outs ] ) self . _residues = np . vstack ( [ out [ 3 ] for out in outs ] ) else : self . coef_ , self . _residues , self . rank_ , self . singular_ = linalg . lstsq ( X , y ) self . coef_ = self . coef_ . T if y . ndim == 1 : self . coef_ = np . ravel ( self . coef_ ) self . _set_intercept ( X_offset , y_offset , X_scale ) return self