fonttian / hyperopt-doc-zh Goto Github PK
View Code? Open in Web Editor NEWGithub开源项目hyperopt系列的中文文档,以及学习教程等
Github开源项目hyperopt系列的中文文档,以及学习教程等
我使用hyperopt中的fmin进行随机森林超参数选择,在选择过程中我输出了产生最优解的max_depth和n_estimators,但我输出的值均比使用fmin返回的值大1
这是我关于hyperopt
from functools import partial
def hyperopt_clt(params, data_x, data_y):
global best
model_clt = RandomForestClassifier(**params)
acc = cross_val_score(model_clt, data_x, data_y).mean()
if acc > best:
best = acc
print('new best:', best, params)
return {'loss': 1 - acc, 'status': STATUS_OK}
space_clf = {
'max_depth': hp.choice('max_depth', range(1, 51)),
'n_estimators': hp.choice('n_estimators', range(1, 21))
}
best = 0
trials_clt = Trials()
hyperopt_clt_partial = partial(hyperopt_clt, data_x = data_x, data_y = data_y)
best_clt = fmin(hyperopt_clt_partial, space = space_clf, algo = tpe.suggest, max_evals = 100, trials = trials_clt)
print(best, '----------------')
print(best_clt, '------------')`
这是我得到的结果
new best:
0.7955077744291005
{'max_depth': 47, 'n_estimators': 12}
new best:
0.8071266849594411
{'max_depth': 5, 'n_estimators': 20}
100%|██████████| 100/100 [00:30<00:00, 3.29trial/s, best loss: 0.19287331504055893]
0.8071266849594411 ----------------
{'max_depth': 4, 'n_estimators': 19} ------------
您好,首先感谢您翻译hyperopt的工作,这对于国内的用户是一个十分有帮助的工作,可是在我使用hyperopt的过程中遇到一个问题,搜索了很多资料人就无法解决,希望作者可以给与帮助,谢谢,问题如下:
我按照fmin文档的代码在我的python环境中执行了以后,出现了一个错误提示,代码和错误如下
`from hyperopt import fmin, tpe, hp
space = hp.uniform('x', -10, 10)
best = fmin(fn=lambda x : x**2,
space=space,
algo=tpe.suggest,
max_evals=100)
print(dir(best))`
File "D:\Anaconda3\lib\site-packages\hyperopt\fmin.py", line 314, in fmin
pass_expr_memo_ctrl=pass_expr_memo_ctrl)
File "D:\Anaconda3\lib\site-packages\hyperopt\base.py", line 786, in init
pyll.toposort(self.expr)
File "D:\Anaconda3\lib\site-packages\hyperopt\pyll\base.py", line 715, in toposort
assert order[-1] == expr
TypeError: 'generator' object is not subscriptable
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.