LSTM时间步骤?
每个人的下午好,
我是编程的新手,所以很抱歉,如果我对问题的愚蠢评论,
我正在建立一个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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论