Keras-Hyperopt(KOPT);Hyper-Parameter Tuning for Keras using Hyperopt.
kopt的Python项目详细描述
#Kopt-Keras的超参数优化
[![构建状态](https://travis-ci.org/avsecz/keras-hyperopt.svg?branch=master)(https://travis ci.org/avsecz/keras hyperopt)
[![许可证](https://img.shields.io/github/license/mashape/apistatus.svg?maxage=2592000)(https://github.com/avsecz/keras hyperopt/blob/master/license)
keras.layers as kl
从keras.optimizers导入adam
kopt和hyoperot导入
从kopt导入compilefn、kmongotrials、test\fn
从hyperopt导入fmin、tpe、hp、status\u ok、trials
定义数据函数返回训练,(验证,测试)数据
def data(max_features=5000,maxlen=80):
(x_train,y_train),(x_test,y_test)=imdb.load_data(num_words=max_features)
x_train=sequence.pad_sequences(x_train,maxlen=maxlen)
x_test=sequence.pad_sequences(x_test,maxlen=maxlen)
返回(x_列[:100],y_列[:100],max_特征),(x_测试,y_测试)
定义返回编译的keras模型的模型函数
def model(train_data,lr=0.001,
embedding_dims=128,rnn_units=64,
dropout=0.2):
提取数据维度
max_features=train_data[2]
model=sequential()
model.add(kl.embedding(max_features,嵌入dims)
model.add(kl.lstm(rnn_units,dropout=dropout,recurrent_dropout=dropout))
model.add(kl.dense(1,activation='sigmoid')
model.compile(loss='binary_crossentropy',
optimizer=adam(lr=lr),
metrics=['accurity'])
return model
对于
LoSuffMeimeCyMalth=“max”,尝试最大化度量
ValueSimultSe==2,使用20%的验证集的训练数据
SaveEnMease=“Best'”、“γ检查点”的最佳模型
SaveSuffReals=真,#将结果另存为.json(除mongoDB之外)
save廑dir=“./saved廑models/”)廑存储模型的位置
廑定义超参数范围
廑有关详细信息,请参见https://github.com/hyperopt/hyperopt/wiki/FMin
hyper廑params={
“data”:{
“max廑features”:100,
“maxlen”:80,
,
“模型”:{
“lr”:hp.log uniform(“m_lr”,np.log(1e-4),np.log(1e-2)),.0001-0.01
“嵌入维度”:hp.choice(“m_emb”,(64,128)),
“rnn单元”:64,
“dropout”:hp.uniform(“m_do”,0,0.5),
“拟合”:hp.uniform(“m_do”,0,0.5),
“拟合”:{
“拟合”:20
“时代”:20<<<
“时代”:20<<<<<<<0.br/>}
}
在一个历元的小子集上,依次运行超参数优化(不带任何数据库)
max evals=2)
exp_name,
ip=“localhost”,
port=22334)
best=fmin(objective,hyper_params,trials=试验,algo=tpe.suggest,max-evals=2)
````
>也请参见
-[nbs/imdb-example.ipynb(nbs/imdb-example.ipynb.ipynb)nbs/imdb/imdb/imdb/imdb/example.ipynb)
``简明.hyopt `(`kopt`是从`简明.hyopt ``中移植过来的)简明.hyopt `(`kopt` kopt`是从`简明.hyopt ``中移植过来的)简明.kopt`的文档文档:
br/>-[api文档](https://i12g gagneurweb.in.tum.de/public/docs/简明/hyopt/)
-[jupyter笔记本](https://github.com/gagneurlab/简明/blob/master/nbs/hyper-parameter\u optimization.ipynb)
[![构建状态](https://travis-ci.org/avsecz/keras-hyperopt.svg?branch=master)(https://travis ci.org/avsecz/keras hyperopt)
[![许可证](https://img.shields.io/github/license/mashape/apistatus.svg?maxage=2592000)(https://github.com/avsecz/keras hyperopt/blob/master/license)
keras.layers as kl
从keras.optimizers导入adam
kopt和hyoperot导入
从kopt导入compilefn、kmongotrials、test\fn
从hyperopt导入fmin、tpe、hp、status\u ok、trials
定义数据函数返回训练,(验证,测试)数据
def data(max_features=5000,maxlen=80):
(x_train,y_train),(x_test,y_test)=imdb.load_data(num_words=max_features)
x_train=sequence.pad_sequences(x_train,maxlen=maxlen)
x_test=sequence.pad_sequences(x_test,maxlen=maxlen)
返回(x_列[:100],y_列[:100],max_特征),(x_测试,y_测试)
定义返回编译的keras模型的模型函数
def model(train_data,lr=0.001,
embedding_dims=128,rnn_units=64,
dropout=0.2):
提取数据维度
max_features=train_data[2]
model=sequential()
model.add(kl.embedding(max_features,嵌入dims)
model.add(kl.lstm(rnn_units,dropout=dropout,recurrent_dropout=dropout))
model.add(kl.dense(1,activation='sigmoid')
model.compile(loss='binary_crossentropy',
optimizer=adam(lr=lr),
metrics=['accurity'])
return model
对于
LoSuffMeimeCyMalth=“max”,尝试最大化度量
ValueSimultSe==2,使用20%的验证集的训练数据
SaveEnMease=“Best'”、“γ检查点”的最佳模型
SaveSuffReals=真,#将结果另存为.json(除mongoDB之外)
save廑dir=“./saved廑models/”)廑存储模型的位置
廑定义超参数范围
廑有关详细信息,请参见https://github.com/hyperopt/hyperopt/wiki/FMin
hyper廑params={
“data”:{
“max廑features”:100,
“maxlen”:80,
,
“模型”:{
“lr”:hp.log uniform(“m_lr”,np.log(1e-4),np.log(1e-2)),.0001-0.01
“嵌入维度”:hp.choice(“m_emb”,(64,128)),
“rnn单元”:64,
“dropout”:hp.uniform(“m_do”,0,0.5),
“拟合”:hp.uniform(“m_do”,0,0.5),
“拟合”:{
“拟合”:20
“时代”:20<<<
“时代”:20<<<<<<<0.br/>}
}
在一个历元的小子集上,依次运行超参数优化(不带任何数据库)
max evals=2)
exp_name,
ip=“localhost”,
port=22334)
best=fmin(objective,hyper_params,trials=试验,algo=tpe.suggest,max-evals=2)
````
>也请参见
-[nbs/imdb-example.ipynb(nbs/imdb-example.ipynb.ipynb)nbs/imdb/imdb/imdb/imdb/example.ipynb)
``简明.hyopt `(`kopt`是从`简明.hyopt ``中移植过来的)简明.hyopt `(`kopt` kopt`是从`简明.hyopt ``中移植过来的)简明.kopt`的文档文档:
br/>-[api文档](https://i12g gagneurweb.in.tum.de/public/docs/简明/hyopt/)
-[jupyter笔记本](https://github.com/gagneurlab/简明/blob/master/nbs/hyper-parameter\u optimization.ipynb)