我正在尝试使用来自Physionet/Apnea-ECG 的数据集构建 GRU 模型来预测阻塞性睡眠呼吸暂停,这里是我的代码:
model = Sequential()
model.add(GRU(128, input_shape=(sequence_length,2), use_bias=True, dropout=0.1, recurrent_dropout=0.1, return_sequences=True))
model.add(GRU(128, use_bias=True, dropout=0.1, recurrent_dropout=0.1))
model.add(Dense(32))
model.add(Dense(1, activation="sigmoid"))
opt = Adam(learning_rate=1e-3)
model.compile(loss="binary_crossentropy", optimizer=opt, metrics=['accuracy'])
model.summary()
history = model.fit(X_train, y_train, epochs=50, batch_size=128, verbose=1, callbacks=[checkpointer], validation_data=(X_val, y_val))
结果在这里
Epoch 00045: val_accuracy did not improve from 0.84295
Epoch 46/50
78/78 [==============================] - 131s 2s/step - loss: 0.1315 - accuracy: 0.9478 -
val_loss: 0.5268 - val_accuracy: 0.8451
Epoch 00046: val_accuracy improved from 0.84295 to 0.84508, saving model to
/content/drive/MyDrive/Colab Notebooks/Model/ModelGRU/CheckpointGRU_1.h5
Epoch 47/50
78/78 [==============================] - 132s 2s/step - loss: 0.1343 - accuracy: 0.9455 -
val_loss: 0.5138 - val_accuracy: 0.8332
Epoch 00047: val_accuracy did not improve from 0.84508
Epoch 48/50
78/78 [==============================] - 130s 2s/step - loss: 0.1127 - accuracy: 0.9549 -
val_loss: 0.5415 - val_accuracy: 0.8411
Epoch 00048: val_accuracy did not improve from 0.84508
Epoch 49/50
78/78 [==============================] - 131s 2s/step - loss: 0.1125 - accuracy: 0.9581 -
val_loss: 0.5661 - val_accuracy: 0.8344
Epoch 00049: val_accuracy did not improve from 0.84508
Epoch 50/50
78/78 [==============================] - 132s 2s/step - loss: 0.1075 - accuracy: 0.9583 -
val_loss: 0.6059 - val_accuracy: 0.8393
Epoch 00050: val_accuracy did not improve from 0.84508
Saved model to disk
103/103 [==============================] - 9s 89ms/step - loss: 0.6051 - accuracy: 0.8354
accuracy: 83.54%
如果我在这个模型中添加注意力层,它会改善结果吗?如果添加注意力层会提高准确性/模型,如何添加层?请有人帮我改进这个模型