'Fit estimator.
Parameters
X : array-like or sparse matrix, shape (n_samples, n_features)
The input samples. Use ``dtype=np.float32`` for maximum
efficiency. Sparse matrices are also supported, use sparse
``csc_matrix`` for maximum efficiency.
sample_weight : array-like, shape = [n_samples] or None
Sample weights. If None, then samples are equally weighted.
Returns
self : object
Returns self.'

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

    X = check_array(X, accept_sparse=['csc'])
    if issparse(X):
        X.sort_indices()
    rnd = check_random_state(self.random_state)
    y = rnd.uniform(size=X.shape[0])
    n_samples = X.shape[0]
    if isinstance(self.max_samples, six.string_types):
        if (self.max_samples == 'auto'):
            max_samples = min(256, n_samples)
        else:
            raise ValueError(('max_samples    (%s)    is    not    supported.Valid    choices    are:    "auto",    int    orfloat' % self.max_samples))
    elif isinstance(self.max_samples, INTEGER_TYPES):
        if (self.max_samples > n_samples):
            warn(('max_samples    (%s)    is    greater    than    the    total    number    of    samples    (%s).    max_samples    will    be    set    to    n_samples    for    estimation.' % (self.max_samples, n_samples)))
            max_samples = n_samples
        else:
            max_samples = self.max_samples
    else:
        if (not (0.0 < self.max_samples <= 1.0)):
            raise ValueError(('max_samples    must    be    in    (0,    1],    got    %r' % self.max_samples))
        max_samples = int((self.max_samples * X.shape[0]))
    self.max_samples_ = max_samples
    max_depth = int(np.ceil(np.log2(max(max_samples, 2))))
    super(IsolationForest, self)._fit(X, y, max_samples, max_depth=max_depth, sample_weight=sample_weight)
    self.threshold_ = (- sp.stats.scoreatpercentile((- self.decision_function(X)), (100.0 * (1.0 - self.contamination))))
    return self
