BayesSearchCV - lightgbm - early stopping - "ValueError: not enough values to unpack"

BayesSearchCV - lightgbm - early stopping - "ValueError: not enough values to unpack"

你能帮我解决下面的问题吗?非常感谢。

没有 fit_params=fit_params,下面的代码工作正常,但我想尝试使用 lgbm 提前停止。 我确实尝试搜索线索,但发现资源有限,但一些 github 来自 lightgbm 和 BayesSearchCV 的问题。

lg = lgb.LGBMClassifier(random_state=42, n_jobs=-1, objective='multiclass', n_estimators=5000)

fullPipeline = Pipeline(steps=[
    ('scaler', StandardScaler()),
    ('model', lg)
])

param_space =  {'model__max_depth': [2, 63],
    'model__num_leaves': [7, 4095],
}

fit_params = {
    'early_stopping_rounds':30,
    'eval_metric':'accuracy',
    'eval_set':[(xValid, yValid)],
}

BSLGB = BayesSearchCV(fullPipeline, param_space, random_state=42, scoring='accuracy', cv=5, n_iter=50, verbose=3, n_jobs=-1,
                     fit_params=fit_params)
%time BSLGB.fit(xTrain.astype(float), yTrain)

异常:

ValueError                                Traceback (most recent call last)
<timed eval> in <module>

C:\Anaconda3x64\envs\ml\lib\site-packages\skopt\searchcv.py in fit(self, X, y, groups, callback)
    652                 optim_result = self._step(
    653                     X, y, search_space, optimizer,
--> 654                     groups=groups, n_points=n_points_adjusted
    655                 )
    656                 n_iter -= n_points

C:\Anaconda3x64\envs\ml\lib\site-packages\skopt\searchcv.py in _step(self, X, y, search_space, optimizer, groups, n_points)
    548         refit = self.refit
    549         self.refit = False
--> 550         self._fit(X, y, groups, params_dict)
    551         self.refit = refit
    552 

C:\Anaconda3x64\envs\ml\lib\site-packages\skopt\searchcv.py in _fit(self, X, y, groups, parameter_iterable)
    401                 error_score=self.error_score
    402             )
--> 403             for parameters in parameter_iterable
    404             for train, test in cv_iter)
    405 

C:\Anaconda3x64\envs\ml\lib\site-packages\sklearn\externals\joblib\parallel.py in __call__(self, iterable)
    928 
    929             with self._backend.retrieval_context():
--> 930                 self.retrieve()
    931             # Make sure that we get a last message telling us we are done
    932             elapsed_time = time.time() - self._start_time

C:\Anaconda3x64\envs\ml\lib\site-packages\sklearn\externals\joblib\parallel.py in retrieve(self)
    831             try:
    832                 if getattr(self._backend, 'supports_timeout', False):
--> 833                     self._output.extend(job.get(timeout=self.timeout))
    834                 else:
    835                     self._output.extend(job.get())

C:\Anaconda3x64\envs\ml\lib\site-packages\sklearn\externals\joblib\_parallel_backends.py in wrap_future_result(future, timeout)
    519         AsyncResults.get from multiprocessing."""
    520         try:
--> 521             return future.result(timeout=timeout)
    522         except LokyTimeoutError:
    523             raise TimeoutError()

C:\Anaconda3x64\envs\ml\lib\concurrent\futures\_base.py in result(self, timeout)
    430                 raise CancelledError()
    431             elif self._state == FINISHED:
--> 432                 return self.__get_result()
    433             else:
    434                 raise TimeoutError()

C:\Anaconda3x64\envs\ml\lib\concurrent\futures\_base.py in __get_result(self)
    382     def __get_result(self):
    383         if self._exception:
--> 384             raise self._exception
    385         else:
    386             return self._result

ValueError: not enough values to unpack (expected 2, got 1)

这个问题的根本原因是我将管道而不是模型传递给 BayesSearchCV。同时,我的 fit_params 没有前缀。修复:

fit_params = {
    'model__early_stopping_rounds':30,
    'model__eval_metric':'multi_logloss',
    'model__eval_set':[(xValid, yValid)],
}