LSTM时间步骤?

发布于 2025-01-23 23:22:39 字数 1944 浏览 0 评论 0原文

每个人的下午好,

我是编程的新手,所以很抱歉,如果我对问题的愚蠢评论,

我正在建立一个LSTM模型,其中我有4个不同的输入,例如空气临时,空气湿度,风速等。我需要产生风力预测的输出。

我的数据集为一年,时间步长为1小时。我首先在制作LSTM时挣扎,因为我需要输入维度为3D Andi在网上找到了解决方案并应用了解决方案。但是现在,我需要更改时间步骤,以查看模型中表现更好的情况,但是我对如何更改它一无所知。

我的代码看起来像:

import tensorflow as tf
import csv
from sklearn.model_selection import train_test_split
import numpy as np
import matplotlib.pyplot as plt
import time

#Read DATA
with open("full_year_data.csv") as f:
    reader = csv.reader(f)
    next(reader)
    data = []
    for row in reader:
        data.append({
            "inputs": [float(cell) for cell in row[:4]],
            "output": [float(cell) for cell in row[4:]]
        })

#separate data into training and testing groups
inputs = [row["inputs"] for row in data]
inputs = np.array(inputs) #shape = (743, 4)
output = [row["output"] for row in data]
output = np.array(output) #shape= (743,1)

X_training, X_testing, y_training, y_testing = train_test_split(
    inputs, output, test_size=0.25
)


X_training = np.expand_dims(X_training,1)
X_testing = np.expand_dims(X_testing,1)

nodes_hidden = 
Learning_algorithm = tf.keras.optimizers.Adam()

model2 = tf.keras.models.Sequential()
model2.add(tf.keras.layers.LSTM(units = nodes_hidden, return_sequences =True, input_shape=X_training.shape[1:], activation='relu'))
model2.add(tf.keras.layers.LSTM(units = nodes_hidden, return_sequences =True, activation='relu'))
model2.add(tf.keras.layers.LSTM(units = nodes_hidden, return_sequences =True, activation='relu'))
model2.add(tf.keras.layers.LSTM(units = nodes_hidden, return_sequences =True, activation='relu'))
model2.add(tf.keras.layers.Dense(1, activation='sigmoid'))

model2.compile(optimizer = 'adam', loss = 'mean_squared_error')

model2.fit(X_training, y_training, epochs=100, batch_size=0)
model2.evaluate(X_testing, y_testing, verbose=2)

我正在使用TensorFlow和Keras制作LSTM模型,关于如何更改我的时间步骤的任何帮助,将非常感谢

您的时间!

Good afternoon to everyone,

I am kind of a newbie in programming so I am sorry if I make stupid comments of questions

I was building an LSTM model in which I have 4 different inputs such as air temp, air humidity, wind speed etc... and I need to produce an output of wind power forecast.

MY dataset is one year long and the time step is 1 hour. I first struggled when making the LSTM as I needed my input dimension to be 3D andI found a solution online and applied it. But now I need to change my time step to see what performs better in my model but I do not have any idea in how to change it.

My code looks like:

import tensorflow as tf
import csv
from sklearn.model_selection import train_test_split
import numpy as np
import matplotlib.pyplot as plt
import time

#Read DATA
with open("full_year_data.csv") as f:
    reader = csv.reader(f)
    next(reader)
    data = []
    for row in reader:
        data.append({
            "inputs": [float(cell) for cell in row[:4]],
            "output": [float(cell) for cell in row[4:]]
        })

#separate data into training and testing groups
inputs = [row["inputs"] for row in data]
inputs = np.array(inputs) #shape = (743, 4)
output = [row["output"] for row in data]
output = np.array(output) #shape= (743,1)

X_training, X_testing, y_training, y_testing = train_test_split(
    inputs, output, test_size=0.25
)


X_training = np.expand_dims(X_training,1)
X_testing = np.expand_dims(X_testing,1)

nodes_hidden = 
Learning_algorithm = tf.keras.optimizers.Adam()

model2 = tf.keras.models.Sequential()
model2.add(tf.keras.layers.LSTM(units = nodes_hidden, return_sequences =True, input_shape=X_training.shape[1:], activation='relu'))
model2.add(tf.keras.layers.LSTM(units = nodes_hidden, return_sequences =True, activation='relu'))
model2.add(tf.keras.layers.LSTM(units = nodes_hidden, return_sequences =True, activation='relu'))
model2.add(tf.keras.layers.LSTM(units = nodes_hidden, return_sequences =True, activation='relu'))
model2.add(tf.keras.layers.Dense(1, activation='sigmoid'))

model2.compile(optimizer = 'adam', loss = 'mean_squared_error')

model2.fit(X_training, y_training, epochs=100, batch_size=0)
model2.evaluate(X_testing, y_testing, verbose=2)

I am using Tensorflow and keras to make my LSTM model, any help on how I can change my time steps for testing will be really appreciate it

Thanks for yout time!

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

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

发布评论

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