训练与验证损失图的意义

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

训练与验证损失图

以下是训练数据的样本:

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

日期时间和ID(用户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 = 60x_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)//10batch_size = 256train_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_sizeepochs = 10single_step_history = single_step_model.fit(train_data_single, epochs=epochs,                                            steps_per_epoch=evaluation_interval,                                            validation_data=test_data_single,                                            validation_steps=50)

回答:

如果训练损失和验证损失之间的差距很大,说明你的模型出现了过拟合。如果训练损失很大,说明你的模型出现了欠拟合。如果你的训练损失和验证损失重叠或彼此接近,说明你的模型现在适合用于预测。

这里的模型出现了过拟合

enter image description here

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注