Hyperopt调整参数被卡住

编程入门 行业动态 更新时间:2024-10-23 13:26:15
本文介绍了Hyperopt调整参数被卡住的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在测试使用hyperopt库调整SVM的参数. 通常,当我执行此代码时,进度条停止并且代码被卡住. 我不明白为什么.

I'm testing to tune parameters of SVM with hyperopt library. Often, when i execute this code, the progress bar stop and the code get stuck. I do not understand why.

这是我的代码:

from hyperopt import fmin, tpe, hp, STATUS_OK, Trials X_train = normalize(X_train) def hyperopt_train_test(params): if 'decision_function_shape' in params: if params['decision_function_shape'] == "ovo": params['break_ties'] = False clf = svm.SVC(**params) y_pred = clf.fit(X_train, y_train).predict(X_test) return precision_recall_fscore_support(y_test, y_pred, average='macro')[0] space4svm = { 'C': hp.uniform('C', 0, 20), 'kernel': hp.choice('kernel', ['linear', 'sigmoid', 'poly', 'rbf']), 'degree': hp.uniform('degree', 10, 30), 'gamma': hp.uniform('gamma', 10, 30), 'coef0': hp.uniform('coef0', 15, 30), 'shrinking': hp.choice('shrinking', [True, False]), 'probability': hp.choice('probability', [True, False]), 'tol': hp.uniform('tol', 0, 3), 'decision_function_shape': hp.choice('decision_function_shape', ['ovo', 'ovr']), 'break_ties': hp.choice('break_ties', [True, False]) } def f(params): print(params) precision = hyperopt_train_test(params) return {'loss': -precision, 'status': STATUS_OK} trials = Trials() best = fmin(f, space4svm, algo=tpe.suggest, max_evals=35, trials=trials) print('best:') print(best)

推荐答案

我建议限制参数的空间,看看是否可行.将probability参数固定为False,然后查看模型是否训练.另外,根据文档,伽玛值必须为{‘scale’, ‘auto’}.

I would suggest restricting the space of your parameters and see if that works. Fix the probability parameter to False and see if the model trains. Also, gamma needs to be {‘scale’, ‘auto’} according to the documentation.

还要在每次迭代时打印出params,以更好地了解哪种组合会导致模型卡住.

Also at every iteration print out your params to better understand which combination is causing the model to get stuck.

更多推荐

Hyperopt调整参数被卡住

本文发布于:2023-11-23 18:34:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622471.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   Hyperopt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!