LSTM从数字序列预测数字

发布于 2025-02-07 06:45:34 字数 1882 浏览 0 评论 0 原文

我正在尝试训练LSTM,以预测一系列数字的一些数字。我的X数据集具有33个功能,而我的Y数据集则具有4个变量,我必须为每个X示例预测。例如:

XDF:

“在此处输入图像描述”

ydf:

“在此处输入映像”

在我将x,y转换为numpy数组并重塑数据后,我构建的数据我以下模型:

我得到以下结果,损失巨大和明显的过度拟合。有什么想法我做错了什么,我得到了这些结果?谢谢。

XDF:

ydf: https://drive.google.com/file/d/1rkjwl1fiiqdyjkrvl7zqktoxie8ftbxa/view?usp = sharing?usp = sharing

更新

我的代码和以下方式更新了,它似乎可以更好地工作。仍然巨大的损失和过度匹配,但是经过一些时代,似乎有一段时间的效果很好。关于如何减少损失和过度拟合的任何建议将不胜感激。

X = X.reshape((X.shape[0], 33, 1)) # (5850, 33, 1)
model = tf.keras.Sequential()
model.add(layers.LSTM(50, activation='relu', input_shape=(33, 1)))
model.add(layers.Dense(4))
model.add(layers.Dense(4))
model.add(layers.Dense(4))
early_stopping = EarlyStopping(monitor='val_loss', patience=42)  
model.compile(optimizer=tf.keras.optimizers.Adam(0.01), loss=tf.keras.losses.MeanSquaredError(), metrics=['accuracy'])
model.fit(X, y, epochs=200, verbose=1, validation_split = 0.2)

I am trying to train an LSTM to predict some numbers from a sequence of number. My X dataset has 33 features and my Y dataset has 4 variables that I have to predict for each X sample. For example:

Xdf:

enter image description here

Ydf:

enter image description here

After I turn X, y to numpy arrays and reshape the data I build the below model:

enter image description here

I get the following results with huge loss and distinct overfitting. Any ideas what I am doing wrong and I am getting these results? Thanks.

enter image description here

Xdf: https://drive.google.com/file/d/1wH56E0M3ok1MGWzU6FGKgDJF7EZfL_7f/view?usp=sharing

ydf: https://drive.google.com/file/d/1RkjWl1FIiQDyjkRvl7ZQKTOXIE8FtBXA/view?usp=sharing

UPDATE

I edited my code the following way and it seems to bee working a tiny bit better. Still huge loss and overfitting but after some epochs it seemed it worked fine for a while. Any suggestions on how to reduce loss and overfitting would be appreciated.

X = X.reshape((X.shape[0], 33, 1)) # (5850, 33, 1)
model = tf.keras.Sequential()
model.add(layers.LSTM(50, activation='relu', input_shape=(33, 1)))
model.add(layers.Dense(4))
model.add(layers.Dense(4))
model.add(layers.Dense(4))
early_stopping = EarlyStopping(monitor='val_loss', patience=42)  
model.compile(optimizer=tf.keras.optimizers.Adam(0.01), loss=tf.keras.losses.MeanSquaredError(), metrics=['accuracy'])
model.fit(X, y, epochs=200, verbose=1, validation_split = 0.2)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文