yangwohenmai / lstm Goto Github PK
View Code? Open in Web Editor NEW基于LSTM的时间序列预测研究
基于LSTM的时间序列预测研究
LSTM/LSTM系列/LSTM单变量4/完整的LSTM案例.py
Lines 47 to 57 in 432457d
shape本来就是这样的吧,看不懂这里的代码要做什么。
Moth=1, Predicted=nan, Expected=339.700000
Moth=2, Predicted=nan, Expected=440.400000
Moth=3, Predicted=nan, Expected=315.900000
Moth=4, Predicted=nan, Expected=439.300000
Moth=5, Predicted=nan, Expected=401.300000
Moth=6, Predicted=nan, Expected=437.400000
Moth=7, Predicted=nan, Expected=575.500000
Moth=8, Predicted=nan, Expected=407.600000
Moth=9, Predicted=nan, Expected=682.000000
Moth=10, Predicted=nan, Expected=475.300000
Moth=11, Predicted=nan, Expected=581.300000
Moth=12, Predicted=nan, Expected=646.900000
请问这个是因为什么呢,训练结果中每一项的预测值都是空值
你好,LSTM/stock_predict/stock_predict_2.py脚本中以batch内的数据和各自对应行的股价做label,并没有达到给予前time_step天预测下一天的作用
您好,看了您的代码,受益匪浅,但是针对自己的问题,还有一些地方不太清楚,如果您有时间,希望你可以帮忙解答,万分感谢!
问题:现在网上很多的LSTM的实例讲解,大都是针对一列数据,如您代码中的乘客、香皂等。我现在想做的是一年内的每日降水,且我有三十个站点,这样的话,我的原始数据就是366*30的数据表,我想问一下,针对多条数据,在进行数据输入重构的时候应该怎么做?
代码修改如下:
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from tensorflow.keras.layers import LSTM
出现问题的代码块:
def fit_lstm(train, n_lag, n_seq, n_batch, nb_epoch, n_neurons):
# (train, 历史1lag, 预测3个步长, 用1 batch数据, 15网络次数_权重更新, 1个神经元)
# 重塑训练数据格式 [samples, timesteps, features]
X, y = train[:, 0:n_lag], train[:, n_lag:] # 1列22个历史数据,3列22个未来数据
X = X.reshape(X.shape[0], 1, X.shape[1]) # (22,1,1)
# 配置一个LSTM神经网络,添加网络参数
model = Sequential()
#1 model.add(LSTM(n_neurons,input_length=X.shape[1], input_dim=X.shape[2])) #TEST: input_length
#1 return Unrecognized keyword arguments passed to LSTM: {'input_length': 1}
#2 model.add(LSTM(units=n_neurons,batch_size=n_batch,input_shape=(X.shape[1], X.shape[2]))) #TEST: batch_size
#2 return Unrecognized keyword arguments passed to LSTM: {'batch_size': 1}
#3 model.add(LSTM(units=n_neurons,activation='tanh',batch_input_shape=(None, X.shape[1], X.shape[2]),stateful=True)) #TEST: batch_input_shape
#3 return Unrecognized keyword arguments passed to LSTM: {'batch_input_shape': (1, 1, 1)}
model.add(LSTM(units=n_neurons,input_shape=(X.shape[1], X.shape[2])))
# return 'Sequential' object has no attribute 'reset_states'
# stateful = True --> 需要shuffle = False
model.add(Dense(y.shape[1]))
model.compile(loss='mean_squared_error', optimizer='adam')
# 调用网络,迭代数据对神经网络进行训练,最后输出训练好的网络模型
for i in range(nb_epoch):
model.fit(X, y, epochs=1, batch_size=n_batch, verbose=0, shuffle=False)
model.reset_states()
return model
model = fit_lstm(train, n_lag, n_seq, n_batch, n_epochs, n_neurons)
尝试各种不同的add lstm的方法,均失败
安装包版本:
tensorflow 2.16.1
keras 3.2.1
python 3.9.19
Hello! Yes, you are correct. In the model definition, the test set and validation set appear to be the same dataset. According to my understanding, they should not be the same dataset.
您好,我在series_to_supervised函数中输入n_in>1的情况时,会出现反归一化报错的问题,提示此时反归一化的数据alueError: operands could not be broadcast together with shapes,请问该如何解决呢,谢谢!
您好,想问您一下,如果我有一系列时间和对应的数值数据,我想预测未来一周的数据情况,可以通过您的哪个框架实现呢?
你好,我想请教一下,我学习了一下LSTM多变量3这个完整的算例,结果看上去预测值会比实际值滞后一格,请问这是为什么。从代码上看标签都是取得数据重构后最后一列的数据,这个现象是正常的嘛。
![]()
是正常的,主要原因是这是这个网络只是一个用于学习的基本的简单网络,以及训练数据集并不足够,并没有训练得到很好的效果。如果想进一步提高准确率,需要对网络模型进行进一步的优化
补充多问一下,主要的运行过程中最后计算得到的RMSE是根据这个错位结果来的,导致RMSE看上去挺大的。别的算例里面有训练数据集不足的,确实是看上去是简单的平移,这个算例初始的训练集是一年,我把它增加到两年三年好像也没有改善,麻烦请教一下训练集大概要是多少才能不出现这种现象。
另外,真的很感谢,算例讲得其实很清楚,有很多注释,算是我神经网络的入门学习资料了!
Originally posted by @Zhujh0224 in #4 (comment)
这里面没说那些包的版本啊,比如tensorflow,具体的版本没说
ModuleNotFoundError: No module named 'tensorflow.compat'
大佬,你好,请问如何预测2个变量组成的数据呢,比如我想预测延时率、丢包率两个结果,求大佬指点
不是预测测试集,而是完全后面未发生的未来一周或者其他一段时间的数据
尝试做了log更改 没解决
请问作者tensorflow的版本号是多少?我用LSTM调了很久,效果都很差,不知道关键点在哪
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.