'Fit the model using X, y as training data.
Parameters
X : array-like, shape [n_samples, n_features]
Training data.
y : array-like, shape [n_samples]
Target values. Will be cast to X\'s dtype if necessary
Returns
self : object
returns an instance of self.'

def fit(self, X, y):

    (X, y) = check_X_y(X, y, y_numeric=True, ensure_min_features=2, estimator=self)
    X = as_float_array(X, copy=False, force_all_finite=False)
    cv = check_cv(self.cv, classifier=False)
    max_iter = (min(max(int((0.1 * X.shape[1])), 5), X.shape[1]) if (not self.max_iter) else self.max_iter)
    cv_paths = Parallel(n_jobs=self.n_jobs, verbose=self.verbose)((delayed(_omp_path_residues)(X[train], y[train], X[test], y[test], self.copy, self.fit_intercept, self.normalize, max_iter) for (train, test) in cv.split(X)))
    min_early_stop = min((fold.shape[0] for fold in cv_paths))
    mse_folds = np.array([(fold[:min_early_stop] ** 2).mean(axis=1) for fold in cv_paths])
    best_n_nonzero_coefs = (np.argmin(mse_folds.mean(axis=0)) + 1)
    self.n_nonzero_coefs_ = best_n_nonzero_coefs
    omp = OrthogonalMatchingPursuit(n_nonzero_coefs=best_n_nonzero_coefs, fit_intercept=self.fit_intercept, normalize=self.normalize)
    omp.fit(X, y)
    self.coef_ = omp.coef_
    self.intercept_ = omp.intercept_
    self.n_iter_ = omp.n_iter_
    return self
