flennerhag / mlens

ML-Ensemble – high performance ensemble learning
http://ml-ensemble.com
MIT License
843 stars 108 forks source link

ValueError: Found array with 0 sample(s) (shape=(0, 13)) while a minimum of 1 is required. #114

Closed cliffrunner closed 5 years ago

cliffrunner commented 5 years ago

Hello,

I modified the sample code in tutorial so that it could work for a regression problem. Please ignore the model and parameter selection, it is just for testing.

base_learners = [Lasso(),Ridge()]

meta_learners = [('rf', RandomForestRegressor(random_state=seed))]

learner1 = SuperLearner(random_state=seed) \
.add(base_learners)

learner2 = SuperLearner(random_state=seed) \
.add(base_learners)

preprocess = {'pre1': [('layer-1', learner1)],
         'pre2': [('layer-1', learner2)]}

params = {'pre1.lasso': {'alpha': uniform(0.2, 0.95)},
      'pre1.ridge': {'alpha': uniform(0.1, 0.5)},
      'pre2.lasso': {'alpha': uniform(0.2, 0.95)},
      'rf': {'n_estimators': randint(10, 100)}
      }

scorer = make_scorer(r2_score)
evaluator = Evaluator(scorer=scorer, random_state=seed, cv=5, n_jobs=1, verbose=2)

evaluator.fit(X, y, meta_learners, params, preprocessing=preprocess, n_iter=4)

X, and y have the shape of (500,13) and (500,). it seems no result is passing into meta regressor in this case:

ValueError: Found array with 0 sample(s) (shape=(0, 13)) while a minimum of 1 is required.

Any help would be appreciated.

flennerhag commented 5 years ago

This seems to be a bug, it should work, but only works for cv=2. For now, I would suggest to use that until we can get this sorted. Most likely, the Evaluator is doing something wrong when creating cv folds.

flennerhag commented 5 years ago

Found it, you forgot to turn model_selection on when using ensemble classes with the Evaluator. You need to add

learner1.model_selection = True
learner2.model_selection = True

and it will run just fine. Remember, once you've completed the model selection step, you need to turn it off:

learner1.model_selection = False
learner2.model_selection = False

For more details, see the ensemble model-selection tutorial.

Sorry the error message wasn't more helpful! Will see what I can do about that.