使用Hyperopt时出现Trials()问题?

时间:2019-02-28 17:24:15

标签: python machine-learning hyperopt

我正在尝试第一次使用Hyperopt在Python中进行超参数调整。我已经阅读了文档,并希望在XgBoost分类器上进行尝试。 “ X_train”和“ y_train”是将数据帧分为测试和训练集之后的数据帧。到目前为止,这是我的代码:

ng-bootstrap

我遇到以下错误,突出显示“ trails = trails”:

#Hyperopt Parameter Tuning
from hyperopt import hp, STATUS_OK, Trials, fmin, tpe
from sklearn.model_selection import cross_val_score


def objective(space):
  print(space)
  clf = xgb.XGBClassifier(objective = space[objective],
                     max_depth = int(space[max_depth]),
                     learning_rate = space[learning_rate],
                     n_estimators = space[n_estimators])


  #eval_set = [(X_train, y_train), (Xcv, Ycv)]
  clf.fit(X_train, y_train, eval_metric='auc',
         early_stopping_rounds=10, verbose=False)

  #pred = clf.predict(X_test)
  auc = cross_val_score(clf, X_train, y_train, cv=3)
  return{'auc':auc, 'status': STATUS_OK }




space = {'booster': 'gbtree',
         'objective': 'binary:logistic',
         'eval': 'auc',
         'max_depth': hp.quniform('max_depth', 1, 100, 5),
         'learning_rate': hp.loguniform('learning_rate', 0.2, 0.3),
         'n_estimators': hp.quniform('n_esimators', 5, 500, 10)}


trials = Trials()
best = fmin(fn=objective,
            space=space,
            algo=tpe.suggest,
            max_evals=3, # change
            trials=trials)

print(best)

我已经进行了一些研究,但未能找到解决此错误的方法。任何帮助都会很棒!

1 个答案:

答案 0 :(得分:0)

根据文档,hp.loguniform只能接受以下三个参数。

INSERT INTO mytemp (price1,price2)
SELECT max(case when timestamp1 > NOW() - INTERVAL 3 HOUR then price1 end),max(case when timestamp2 > NOW() - INTERVAL 3 HOUR then price2 end) 
FROM mytable 

这可能是错误的原因。请检查。