深度学习时间序列LSTM

参考

https://github.com/jaungiers/LSTM-Neural-Network-for-Time-Series-Prediction
https://blog.csdn.net/a819825294/article/details/54376781
之前做了挺长一段时间的时间序列方面的研究。但是感觉我还是学艺不精,用的传统的ARMA,效果极差。后来因为一些事情,研究了一段时间别的方面,最近在老公的鼓励之下,觉得还是努力的尽量的做好吧。
于是现在开始研究LSTM,原理在这里不赘述了,这里说一下网上经典例子的跑通过程吧,仅仅是跑通别人的经典代码,感觉就踩坑无数,这里就是致敬经典,然后说一下

如何避免踩坑。(这里还要提醒一下,因为使用的python版本的问题,在我参考的原文里面

1,xrange改成range

2,len(data)/prediction_len改为int(len(data)/prediction_len)

3,还有一个在代码里要把plot的save放在show之前,不然保存的图片是空白的)

首先,遇到的问题是:ImportError: cannot import name 'isna'方案和问题的根因,我写在我的简书里了

https://www.jianshu.com/p/073e5c02340d

其次,遇到的问题是:

image.png

我搜索了一下,有网友说问题出在了Keras 库的版本太高了
https://blog.csdn.net/zyh2004883/article/details/84337872
image.png

于是我在anaconda里面将Keras的版本降下来了,降成2.1.2了,跑了一下,真的成功了。
image.png

下面是运行结果。

D:\ProgramData\Anaconda3\envs\tensorflow\python.exe D:/pythonworkspace/深度学习时间序列LSTM/1example.py
Using TensorFlow backend.
> Loading data... 
data len: 4172
sequence len: 50
result len: 4121
result shape: (4121, 51)
[['1455.219971', '1399.420044', '1402.109985', '1403.449951', '1441.469971', '1457.599976', '1438.560059', '1432.25', '1449.680054', '1465.150024', '1455.140015', '1455.900024', '1445.569946', '1441.359985', '1401.530029', '1410.030029', '1404.089966', '1398.560059', '1360.160034', '1394.459961', '1409.280029', '1409.119995', '1424.969971', '1424.369995', '1424.23999', '1441.719971', '1411.709961', '1416.829956', '1387.119995', '1389.939941', '1402.050049', '1387.670044', '1388.26001', '1346.089966', '1352.170044', '1360.689941', '1353.430054', '1333.359985', '1348.050049', '1366.420044', '1379.189941', '1381.76001', '1409.170044', '1391.280029', '1355.619995', '1366.699951', '1401.689941', '1395.069946', '1383.619995', '1359.150024', '1392.140015']]
[[0.0, -0.03834466823710192, -0.03649619099406931, -0.03557539137153576, -0.009448743333663301, 0.001635495009297161, -0.011448380541775882, -0.01578453529895929, -0.003806927550748962, 0.006823747060848984, -5.494427068997165e-05, 0.0004673197272937468, -0.006631317046431495, -0.009524323659793943, -0.03689472593143783, -0.031053684597900588, -0.035135585010467096, -0.03893563387606924, -0.0653234142565241, -0.04175314468660485, -0.03156907059791858, -0.03167904297542101, -0.02078723533405935, -0.021199527641721727, -0.0212888646509648, -0.00927694800032397, -0.029899266686190917, -0.026380901695308046, -0.04679703230928234, -0.044859218057006656, -0.03653737789446543, -0.046419048904050575, -0.046013635281535015, -0.07499210234519249, -0.07081398623823587, -0.06495927205770868, -0.06994813088639229, -0.08373990766238593, -0.07364516989576142, -0.06102165223789391, -0.05224641739059799, -0.050480313948357725, -0.03164465023686791, -0.043938334598350504, -0.06844324431003834, -0.06082930537241782, -0.036784837390058, -0.04133397438097686, -0.04920216697603308, -0.06601747427502835, -0.04334736827220198]]
normalise_windows result shape: (4121, 51)
X_train shape: (3709, 50, 1)
y_train shape: (3709,)
X_test shape: (412, 50, 1)
y_test shape: (412,)
> Data Loaded. Compiling...
Compilation Time :  0.038895368576049805
Train on 3523 samples, validate on 186 samples
Epoch 1/1
2018-12-25 15:24:01.158574: W c:\l\tensorflow_1501907206084\work\tensorflow-1.2.1\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE instructions, but these are available on your machine and could speed up CPU computations.
2018-12-25 15:24:01.161823: W c:\l\tensorflow_1501907206084\work\tensorflow-1.2.1\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE2 instructions, but these are available on your machine and could speed up CPU computations.
2018-12-25 15:24:01.163144: W c:\l\tensorflow_1501907206084\work\tensorflow-1.2.1\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE3 instructions, but these are available on your machine and could speed up CPU computations.
2018-12-25 15:24:01.165020: W c:\l\tensorflow_1501907206084\work\tensorflow-1.2.1\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2018-12-25 15:24:01.165745: W c:\l\tensorflow_1501907206084\work\tensorflow-1.2.1\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2018-12-25 15:24:01.168269: W c:\l\tensorflow_1501907206084\work\tensorflow-1.2.1\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2018-12-25 15:24:01.170652: W c:\l\tensorflow_1501907206084\work\tensorflow-1.2.1\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
2018-12-25 15:24:01.171459: W c:\l\tensorflow_1501907206084\work\tensorflow-1.2.1\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.

 512/3523 [===>..........................] - ETA: 16s - loss: 0.0040
1024/3523 [=======>......................] - ETA: 11s - loss: 0.0046
1536/3523 [============>.................] - ETA: 8s - loss: 0.0038 
2048/3523 [================>.............] - ETA: 5s - loss: 0.0031
2560/3523 [====================>.........] - ETA: 3s - loss: 0.0026
3072/3523 [=========================>....] - ETA: 1s - loss: 0.0023
3523/3523 [==============================] - 14s 4ms/step - loss: 0.0021 - val_loss: 0.0012
multiple_predictions shape: (8, 50)
full_predictions shape: (412,)
predicted shape: (412, 1)
point_by_point_predictions shape: (412,)
Training duration (s) :  32.810912132263184

Process finished with exit code 0

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 220,884评论 6 513
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 94,212评论 3 395
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 167,351评论 0 360
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 59,412评论 1 294
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 68,438评论 6 397
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 52,127评论 1 308
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,714评论 3 420
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,636评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 46,173评论 1 319
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 38,264评论 3 339
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,402评论 1 352
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 36,073评论 5 347
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,763评论 3 332
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,253评论 0 23
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,382评论 1 271
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,749评论 3 375
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,403评论 2 358

推荐阅读更多精彩内容