如何修复奇怪的模型精度图?

How to fix strange model accuracy graph?

我正在尝试创建一个用 'b' 预测“a”的模型。

我尝试预测时间序列数据。 共包含72周的训练集数据和32周的验证数据。

我的模型由 LSTM 多层组成。

显示我的 python 代码

def train_lstm(x, y, train_size , epoch=500):
    time_step = x.shape[1]
    dim = x.shape[2]
    layer_size = 16

    x_data = x[:train_size]
    y_data = y[:train_size]
    x_val = x[train_size:]
    y_val = y[train_size:]

    K.clear_session()
    model = Sequential()
    model.add(LSTM(layer_size, input_shape=(time_step, dim), return_sequences=True))
    model.add(LSTM(layer_size, input_shape=(time_step, dim)))
    model.add(Dense(layer_size, activation='relu'))
    model.add(Dense(layer_size, activation='relu'))
    model.add(Dropout(0.3))
    model.add(Dense(1, activation='sigmoid'))
    model.compile(loss='mean_squared_error', optimizer='adam',  metrics=['accuracy'])
    record = model.fit(x_data,y_data,validation_data=(x_val,y_val), epochs=epoch, verbose=0)
    model.reset_states()

    #Print train log 1
    plt.title("loss graph")
    plt.ylabel('loss')
    plt.xlabel('epoch')
    plt.plot(range(0,len(record.history['loss'])),record.history['loss'], '.-', color='black', label='train_loss')
    plt.plot(range(0,len(record.history['val_loss'])),record.history['val_loss'], '.-', color='blue', label='test_loss')
    plt.legend()
    plt.show()
    plt.clf()

    #Print train log 2
    plt.title("acc graph")
    plt.ylabel('accuracy')
    plt.xlabel('epoch')
    plt.plot(range(0,len(record.history['accuracy'])),record.history['accuracy'], '.-', color='black', label='train_loss')
    plt.plot(range(0,len(record.history['val_accuracy'])),record.history['val_accuracy'], '.-', color='blue', label='test_loss')
    plt.legend()
    plt.show()
    plt.clf()

我预测值成功了。 此图显示,随着训练次数的增加,训练损失显着减少。

loss graph
acc graph

但是准确率图很奇怪。 我该如何解决?

它是平坦的,然后,它开始跳跃,然后停止。是的,这很奇怪。但是,您不必为此担心,您需要的是平滑的曲线上升。我建议你的第一件事是降低你的学习率或设置它(我看不到你在哪里设置它)。保持在 3e-5,黄金学习率。然后,玩弄它。如果这不起作用,请减少模型中的层数,然后使用 dropout。但是,首先尝试学习率。