'Fit the random regressor.
Parameters
X : {array-like, sparse matrix}, shape = [n_samples, n_features]
Training vectors, where n_samples is the number of samples
and n_features is the number of features.
y : array-like, shape = [n_samples] or [n_samples, n_outputs]
Target values.
sample_weight : array-like of shape = [n_samples], optional
Sample weights.
Returns
self : object
Returns self.'

def fit(self, X, y, sample_weight=None):

    X = check_array(X, accept_sparse=['csr', 'csc', 'coo'], force_all_finite=False)
    if (self.strategy not in ('mean', 'median', 'quantile', 'constant')):
        raise ValueError(("Unknown    strategy    type:    %s,    expected    'mean',    'median',    'quantile'    or    'constant'" % self.strategy))
    y = check_array(y, ensure_2d=False)
    if (len(y) == 0):
        raise ValueError('y    must    not    be    empty.')
    self.output_2d_ = (y.ndim == 2)
    if (y.ndim == 1):
        y = np.reshape(y, ((-1), 1))
    self.n_outputs_ = y.shape[1]
    check_consistent_length(X, y, sample_weight)
    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.0) 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.output_2d_ 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
