parameters: (self, X, y, sample_weight=None)
return_statement: return self
docstring: Fit the random regressor.
  
          Parameters
          ----------
          X : {array-like, object with finite length or shape}
              Training data, requires length = n_samples
  
          y : array-like of shape (n_samples,) or (n_samples, n_outputs)
              Target values.
  
          sample_weight : array-like of shape (n_samples,), default=None
              Sample weights.
  
          Returns
          -------
          self : object
docstring_summary: Fit the random regressor.
docstring_tokens: Fit the random regressor .
function: def fit(self, X, y, sample_weight=None):
          """Fit the random regressor.
  
          Parameters
          ----------
          X : {array-like, object with finite length or shape}
              Training data, requires length = n_samples
  
          y : array-like of shape (n_samples,) or (n_samples, n_outputs)
              Target values.
  
          sample_weight : array-like of shape (n_samples,), default=None
              Sample weights.
  
          Returns
          -------
          self : object
          """
          allowed_strategies = ("mean", "median", "quantile", "constant")
          if self.strategy not in allowed_strategies:
              raise ValueError("Unknown strategy type: %s, expected one of %s."
                               % (self.strategy, allowed_strategies))
  
          y = check_array(y, ensure_2d=False)
          if len(y) == 0:
              raise ValueError("y must not be empty.")
  
          if y.ndim == 1:
              y = np.reshape(y, (-1, 1))
          self.n_outputs_ = y.shape[1]
  
          check_consistent_length(X, y, sample_weight)
  
          if sample_weight is not None:
              sample_weight = _check_sample_weight(sample_weight, X)
  
          if self.strategy == "mean":
              self.constant_ = np.average(y, axis=0, weights=sample_weight)
  
          elif self.strategy == "median":
              if sample_weight is None:
                  self.constant_ = np.median(y, axis=0)
              else:
                  self.constant_ = [_weighted_percentile(y[:, k], sample_weight,
                                                         percentile=50.)
                                    for k in range(self.n_outputs_)]
  
          elif self.strategy == "quantile":
              if self.quantile is None or not np.isscalar(self.quantile):
                  raise ValueError("Quantile must be a scalar in the range "
                                   "[0.0, 1.0], but got %s." % self.quantile)
  
              percentile = self.quantile * 100.0
              if sample_weight is None:
                  self.constant_ = np.percentile(y, axis=0, q=percentile)
              else:
                  self.constant_ = [_weighted_percentile(y[:, k], sample_weight,
                                                         percentile=percentile)
                                    for k in range(self.n_outputs_)]
  
          elif self.strategy == "constant":
              if self.constant is None:
                  raise TypeError("Constant target value has to be specified "
                                  "when the constant strategy is used.")
  
              self.constant = check_array(self.constant,
                                          accept_sparse=['csr', 'csc', 'coo'],
                                          ensure_2d=False, ensure_min_samples=0)
  
              if self.n_outputs_ != 1 and self.constant.shape[0] != y.shape[1]:
                  raise ValueError(
                      "Constant target value should have "
                      "shape (%d, 1)." % y.shape[1])
  
              self.constant_ = self.constant
  
          self.constant_ = np.reshape(self.constant_, (1, -1))
          return self
function_tokens: def fit ( self , X , y , sample_weight = None ) : allowed_strategies = ( "mean" , "median" , "quantile" , "constant" ) if self . strategy not in allowed_strategies : raise ValueError ( "Unknown strategy type: %s, expected one of %s." % ( self . strategy , allowed_strategies ) ) y = check_array ( y , ensure_2d = False ) if len ( y ) == 0 : raise ValueError ( "y must not be empty." ) if y . ndim == 1 : y = np . reshape ( y , ( - 1 , 1 ) ) self . n_outputs_ = y . shape [ 1 ] check_consistent_length ( X , y , sample_weight ) if sample_weight is not None : sample_weight = _check_sample_weight ( sample_weight , X ) if self . strategy == "mean" : self . constant_ = np . average ( y , axis = 0 , weights = sample_weight ) elif self . strategy == "median" : if sample_weight is None : self . constant_ = np . median ( y , axis = 0 ) else : self . constant_ = [ _weighted_percentile ( y [ : , k ] , sample_weight , percentile = 50. ) for k in range ( self . n_outputs_ ) ] elif self . strategy == "quantile" : if self . quantile is None or not np . isscalar ( self . quantile ) : raise ValueError ( "Quantile must be a scalar in the range " "[0.0, 1.0], but got %s." % self . quantile ) percentile = self . quantile * 100.0 if sample_weight is None : self . constant_ = np . percentile ( y , axis = 0 , q = percentile ) else : self . constant_ = [ _weighted_percentile ( y [ : , k ] , sample_weight , percentile = percentile ) for k in range ( self . n_outputs_ ) ] elif self . strategy == "constant" : if self . constant is None : raise TypeError ( "Constant target value has to be specified " "when the constant strategy is used." ) self . constant = check_array ( self . constant , accept_sparse = [ 'csr' , 'csc' , 'coo' ] , ensure_2d = False , ensure_min_samples = 0 ) if self . n_outputs_ != 1 and self . constant . shape [ 0 ] != y . shape [ 1 ] : raise ValueError ( "Constant target value should have " "shape (%d, 1)." % y . shape [ 1 ] ) self . constant_ = self . constant self . constant_ = np . reshape ( self . constant_ , ( 1 , - 1 ) ) return self