def fit_models(self, X, y):
        """Perform internal cross-validation fit"""

        if (self.verbose):
            sys.stderr.write('\nfitting models:\n')

        if (self.use_bootstrap):
            n = X.shape[0]
            rs = check_random_state(self.random_state)
            self._folds = [_bootstraps(n, rs) for _ in xrange(self.n_folds)]
        else:
            self._folds = list(StratifiedKFold(y, n_folds=self.n_folds))

        select_stmt = "select pickled_model from models where model_idx = ?"
        insert_stmt = """insert into fitted_models
                             (model_idx, fold_idx, pickled_model)
                         values (?,?,?)"""

        db_conn = sqlite3.connect(self.db_file)
        curs = db_conn.cursor()

        for model_idx in xrange(self._n_models):

            curs.execute(select_stmt, [model_idx])
            pickled_model = curs.fetchone()[0]
            model = loads(str(pickled_model))

            model_folds = []

            for fold_idx, fold in enumerate(self._folds):
                train_inds, _ = fold
                model.fit(X[train_inds], y[train_inds])

                pickled_model = buffer(dumps(model))
                model_folds.append((model_idx, fold_idx, pickled_model))

            with db_conn:
                db_conn.executemany(insert_stmt, model_folds)

            if (self.verbose):
                if ((model_idx + 1) % 50 == 0):
                    sys.stderr.write('%d\n' % (model_idx + 1))
                else:
                    sys.stderr.write('.')

        if (self.verbose):
            sys.stderr.write('\n')

        with db_conn:
            stmt = """create index fitted_models_index
                      on fitted_models (model_idx, fold_idx)"""

            db_conn.execute(stmt)

        db_conn.close()
dataset/ETHPy150Open dclambert/pyensemble/ensemble.py/EnsembleSelectionClassifier.fit_models/original