由于我在上一篇文章(How to put KerasClassifier, Hyperopt and Sklearn cross-validation together)中给出了很好的答案,因此非常有用。
我还有其他问题:
如果我将条件搜索空间设置为:
from nltk.corpus import stopwords
stop_words = stopwords.words('english')
sent1 = 'I have a sentence which is a list'
sent2 = 'I have a sentence which is another list'
sent1 = sent1.lower().split()
sent2 = sent2.lower().split()
l = [sent1, sent2]
for n, sent in enumerate(l):
for stop_word in stop_words:
sent = [word for word in sent if word != stop_word]
l[n] = sent
print(l)
如何将超级参数作为create_model函数的输入参数?
我想出了一个解决方案,但不知道这是否合适
second_layer_search_space = \
hp.choice('second_layer',
[
{
'include': False,
},
{
'include': True,
'layer_size': hp.choice('layer_size', np.arange(5, 26, 5)),
}
])
space = {
'second_layer': second_layer_search_space,
'units1': hp.choice('units1', [12, 64]),
'dropout': hp.choice('dropout1', [0.25, 0.5]),
'batch_size': hp.choice('batch_size', [10, 20]),
'epochs': hp.choice('nb_epochs', [2, 3]),
'activation': 'relu'
}