当我使用 Hyperopt 进行贝叶斯优化时,以下代码中出现值错误:
from hpsklearn import HyperoptEstimator, any_classifier
from sklearn.datasets import fetch_openml
from hyperopt import tpe
import numpy as np
# Download the data and split into training and test sets
digits = fetch_openml('mnist_784')
X = digits.data
y = digits.target
test_size = int( 0.2 * len( y ) )
np.random.seed( 100 )
indices = np.random.permutation(len(X))
X_train = X[ indices[:-test_size]]
y_train = y[ indices[:-test_size]]
X_test = X[ indices[-test_size:]]
y_test = y[ indices[-test_size:]]
estim = HyperoptEstimator( classifier=any_classifier('clf'),
algo=tpe.suggest, trial_timeout=300)
estim.fit( X_train, y_train )
print( estim.score( X_test, y_test ) )
print( estim.best_model() )
错误如下:
100%|██████████| 1/1 [05:00<00:00, 300.17s/it, best loss: ?]
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-4-0c8c24abd852> in <module>()
22 algo=tpe.suggest, trial_timeout=300)
23
---> 24 estim.fit( X_train, y_train )
25
26 print( estim.score( X_test, y_test ) )
9 frames
<__array_function__ internals> in argmin(*args, **kwargs)
/usr/local/lib/python3.6/dist-packages/numpy/core/fromnumeric.py in _wrapit(obj, method, *args, **kwds)
45 except AttributeError:
46 wrap = None
---> 47 result = getattr(asarray(obj), method)(*args, **kwds)
48 if wrap:
49 if not isinstance(result, mu.ndarray):
ValueError: attempt to get argmin of an empty sequence
谁能帮我解决这个错误?我尝试了很多次,但这个错误仍然存在。