来自Keras RNN教程的文章:“ RNN 很棘手。批大小的选择很重要,损耗和优化器的选择很重要,等等。某些配置无法融合。”
因此,这是关于在Keras上调整LSTM-RNN的超参数的一个普遍问题。我想知道一种为您的RNN查找最佳参数的方法。
我从Keras'Github上的IMDB示例开始。
主要模型如下:
(X_train, y_train), (X_test, y_test) = imdb.load_data(nb_words=max_features,
test_split=0.2)
max_features = 20000
maxlen = 100 # cut texts after this number of words (among top max_features most common words)
batch_size = 32
model = Sequential()
model.add(Embedding(max_features, 128, input_length=maxlen))
model.add(LSTM(128))
model.add(Dropout(0.5))
model.add(Dense(1))
model.add(Activation('sigmoid'))
# try using different optimizers and different optimizer configs
model.compile(loss='binary_crossentropy',
optimizer='adam',
class_mode="binary")
print("Train...")
model.fit(X_train, y_train, batch_size=batch_size, nb_epoch=3,
validation_data=(X_test, y_test), show_accuracy=True)
score, acc = model.evaluate(X_test, y_test,
batch_size=batch_size,
show_accuracy=True)
print('Test accuracy:', acc)
Test accuracy:81.54321846
81.5是一个不错的成绩,更重要的是,它表明该模型即使没有完全优化也可以运行。
我的数据是时间序列,任务是二进制预测,与示例相同。现在我的问题看起来像这样:
#Training Data
train = genfromtxt(os.getcwd() + "/Data/trainMatrix.csv", delimiter=',', skip_header=1)
validation = genfromtxt(os.getcwd() + "/Data/validationMatrix.csv", delimiter=',', skip_header=1)
#Targets
miniTrainTargets = [int(x) for x in genfromtxt(os.getcwd() + "/Data/trainTarget.csv", delimiter=',', skip_header=1)]
validationTargets = [int(x) for x in genfromtxt(os.getcwd() + "/Data/validationTarget.csv", delimiter=',', skip_header=1)]
#LSTM
model = Sequential()
model.add(Embedding(train.shape[0], 64, input_length=train.shape[1]))
model.add(LSTM(64))
model.add(Dropout(0.5))
model.add(Dense(1))
model.add(Activation('sigmoid'))
# try using different optimizers and different optimizer configs
model.compile(loss='binary_crossentropy',
optimizer='adam',
class_mode="binary")
model.fit(train, miniTrainTargets, batch_size=batch_size, nb_epoch=5,
validation_data=(validation, validationTargets), show_accuracy=True)
valid_preds = model.predict_proba(validation, verbose=0)
roc = metrics.roc_auc_score(validationTargets, valid_preds)
print("ROC:", roc)
ROC:0.5006526
该模型与IMDB基本相同。尽管结果表明它没有学到任何东西。但是,当我使用普通的MLP-NN时,我不会遇到相同的问题,该模型会学习并且分数会增加。我尝试增加时期数并增加或减少LTSM单位的数量,但分数不会增加。
因此,我想知道一种用于调整网络的标准方法,因为从理论上讲,该算法应比专门针对此时间序列数据的多层感知器网络性能更好。