我在Keras中有一个卷积+ LSTM模型,与此类似(参考文献1),我正在用它进行Kaggle竞赛。架构如下所示。我已经在我标记的11000个样本集上进行了训练(两个类别,初始患病率是〜9:1,所以我将1的样本上采样到大约1/1的比例)进行了50个时期的验证,拆分率为20%。有一阵子,但我认为它受到噪音和掉线层的控制。
模型看起来像是在进行出色的训练,最终在整个训练集上得分为91%,但是在对测试数据集进行测试时,绝对是垃圾。
注意:验证准确性高于训练准确性。这与“典型”过度拟合相反。
我的直觉是,考虑到验证的细微差别,该模型仍在设法过于严格地适应输入集而失去概括性。另一个线索是val_acc大于acc,这似乎很可疑。这是最有可能的情况吗?
如果这太适合了,那么增加验证间隔会完全缓解吗,还是我会遇到同样的问题,因为平均而言,每个样本仍会看到整个时期的一半?
该模型:
Layer (type) Output Shape Param # Connected to
====================================================================================================
convolution1d_19 (Convolution1D) (None, None, 64) 8256 convolution1d_input_16[0][0]
____________________________________________________________________________________________________
maxpooling1d_18 (MaxPooling1D) (None, None, 64) 0 convolution1d_19[0][0]
____________________________________________________________________________________________________
batchnormalization_8 (BatchNormal(None, None, 64) 128 maxpooling1d_18[0][0]
____________________________________________________________________________________________________
gaussiannoise_5 (GaussianNoise) (None, None, 64) 0 batchnormalization_8[0][0]
____________________________________________________________________________________________________
lstm_16 (LSTM) (None, 64) 33024 gaussiannoise_5[0][0]
____________________________________________________________________________________________________
dropout_9 (Dropout) (None, 64) 0 lstm_16[0][0]
____________________________________________________________________________________________________
batchnormalization_9 (BatchNormal(None, 64) 128 dropout_9[0][0]
____________________________________________________________________________________________________
dense_23 (Dense) (None, 64) 4160 batchnormalization_9[0][0]
____________________________________________________________________________________________________
dropout_10 (Dropout) (None, 64) 0 dense_23[0][0]
____________________________________________________________________________________________________
dense_24 (Dense) (None, 2) 130 dropout_10[0][0]
====================================================================================================
Total params: 45826
这是拟合模型的调用(自从对输入进行上采样以来,班级权重通常约为1:1):
class_weight= {0:1./(1-ones_rate), 1:1./ones_rate} # automatically balance based on class occurence
m2.fit(X_train, y_train, nb_epoch=50, batch_size=64, shuffle=True, class_weight=class_weight, validation_split=0.2 )
SE有一个愚蠢的规则,我可以发布不超过2个链接,直到我的分数更高为止,因此如果您有兴趣,请参见以下示例:参考1:machinelearningmastery DOT com SLASH序列分类-lstm-recurrent-neural-networks- python-keras