【问题标题】:Training and Validation Loss Graph Meaning训练和验证损失图含义
【发布时间】:2020-05-29 05:36:42
【问题描述】:

这是我第一次尝试创建 LSTM RNN。我对生成的训练损失和验证损失图的含义感到困惑。这是图表的图像:

Training and Validation Loss Graph

这是训练数据的样本:


                        lat         long    trip_id mode_cat
datetime            id              
2011-08-27 06:13:01 20  39.979973   116.305745  1   1
2011-08-27 06:13:02 20  39.979957   116.305688  1   1
2011-08-27 06:13:03 20  39.979960   116.305693  1   1
2011-08-27 06:13:04 20  39.979970   116.305717  1   1
2011-08-27 06:13:05 20  39.979985   116.305732  1   1

Datetime 和 Id (user_id) 被设置为索引。

这里是创建移动窗口和 LSTM 的代码:

def moving_window(dataset_x, dataset_y, past_history):
    data, labels = [], []
    for i in range(past_history, len(dataset_x)):
        indices = range(i-past_history, i)
        data.append(dataset_x[indices])
        labels.append(dataset_y[i])
    return np.array(data), np.array(labels)

past_history = 60

x_train_single, y_train_single = moving_window(dataset_train_x, dataset_train_y, past_history)
x_test_single, y_test_single = moving_window(dataset_test_x, dataset_test_y, past_history)

buffer_size = len(x_train_single)//10
batch_size = 256

train_data_single = tf.data.Dataset.from_tensor_slices((x_train_single, y_train_single))
train_data_single = train_data_single.cache().shuffle(buffer_size).batch(batch_size).repeat()

test_data_single = tf.data.Dataset.from_tensor_slices((x_test_single, y_test_single))
test_data_single = test_data_single.batch(batch_size).repeat()

single_step_model = tf.keras.models.Sequential()
single_step_model.add(tf.keras.layers.LSTM(32,
                                           input_shape=x_train_single.shape[-2:]))
single_step_model.add(tf.keras.layers.Dense(1))

single_step_model.compile(optimizer=tf.keras.optimizers.RMSprop(), loss='mae')

evaluation_interval = len(x_train_single)//batch_size
epochs = 10

single_step_history = single_step_model.fit(train_data_single, epochs=epochs,
                                            steps_per_epoch=evaluation_interval,
                                            validation_data=test_data_single,
                                            validation_steps=50)

【问题讨论】:

  • 请从intro tour 重复how to ask。 “我很困惑”不是问题规范。训练损失和验证损失在很多地方都有很好的记录。我们需要您发布您的图表并准确解释您的困惑。

标签: python tensorflow machine-learning keras deep-learning


【解决方案1】:

如果训练损失和验证损失之间的差距很大,则意味着您的模型过拟合,如果训练损失很大,则意味着您的模型欠拟合。 如果您的训练损失和验证损失重叠或彼此接近,则意味着您的模型现在适合预测。

这里的模型过拟合

【讨论】:

    猜你喜欢
    • 2018-04-05
    • 1970-01-01
    • 1970-01-01
    • 2019-11-29
    • 1970-01-01
    • 2019-04-02
    • 1970-01-01
    • 1970-01-01
    • 2020-09-04
    相关资源
    最近更新 更多