åæ é¢ |
Extreme Event Forecasting with LSTM Autoencoders
ä½ãè
|
Marco Cerliani
ç¿»ãè¯ |
é»é¯ãDooriaãybNeroãèä¹¦å¿ ãéºè°
审ãæ ¡ |
åéã鸢尾ãskura
Photo by Nur Afni Setiyaningrum on Unsplash
对äºæ¯ä¸ªæ°æ®ç§å¦å®¶æ¥è¯´ï¼è¿è¡æ端äºä»¶é¢æµæ¯ä¸ä¸ªç»å¸¸ä¼éå°çå©æ¢¦ã寻寻è§
è§
ï¼æç»äºåç°äºå¤çè¿ä¸ªé®é¢é常æ趣çèµæºãå°±æ个人èè¨ï¼æç¡®å®ç±ä¸äºUberç 究人ååå¸çæ¹æ³ãå¨ä»ä»¬ç论æ
https://eng.
uber.com/neural-networks/
https://arxiv.org/pdf/1709.01907.pdfï¼æ两个çæ¬
ä¸ï¼ä»ä»¬å¼åäºä¸ä¸ªåºäºæºå¨å¦ä¹ ç解å³æ¹æ¡ï¼ç¨äºé¢æµæ¯æ¥ä¹å®¢éæ±ãä»ä»¬çæ¹æ³ä»¥å
¶ç®æ´ææç解éåæäºå®æ½çç¹ç¹èå¼èµ·äºæç注æãæ以æçç®çæ¯ç¨pythonéç°ä»ä»¬çåç°ãæ对è¿ä¸ªææé常满æï¼å¹¶ä¸æç»æè¿æé«äºèªå·±å¯¹åå½é¢æµç认è¯ã
è¿ç¯æç« æéè¦çæ¶è·å¯ä»¥æ¦æ¬ä¸ºï¼
1.å¼åä¸ç§ç¨³å®çæ¹æ³æ¥è¯ä¼°åæ¯è¾keras模åï¼åæ¶é¿å
æéç§åçæå¨çé®é¢ï¼ï¼
2.å®ç°äºä¸ä¸ªç®åèæºè½çLSTMèªç¼ç å¨ï¼ç¨äºæ°ç¹å¾çå建ï¼
3.éè¿ç®åçæå·§æé«æ¶é´åºåçé¢æµæ§è½ï¼åè§ä¸é¢çæ¥éª¤ï¼ï¼
4.å¤çåµå¥æ°æ®éï¼å³æ们è§å¯å°çå±äºä¸åå®ä½çé®é¢ï¼ä¾å¦ï¼ä¸åååº/å¼æ/人åçæ¶é´åºåçï¼ãä»è¿ä¸ªæä¹ä¸è¯´ï¼æ们åªä¸ºææ人å¼åä¸ä¸ªé«æ§è½ç模åï¼
ä¿æéå®ï¼è®©æ们ä¸æ¥ä¸æ¥å¼å§å§ã
é®é¢æ¦è¿°
对äºUberæ¥è®²ï¼å¯¹åºè¡ï¼ç¹å«æ¯ç¹æ®æ¥æéï¼çåç¡®é¢æµæ许å¤éè¦ç好å¤ï¼æ´ææç驾驶ååé
ï¼ä»¥åå°å¸æºççå¾
æ¶é´ï¼é¢ç®åå
¶ä»ç¸å
³ä»»å¡ã
为äºæ´åç¡®å°é¢æµé©¾é©¶å对å
±äº«è½¦è¾çéæ±ï¼Uberçç 究人åå¼åäºä¸ç§ç¨äºæ¶é´åºåé¢æµçé«æ§è½æ¨¡åãä»ä»¬è½å¤å°ä¸ä¸ªæ¨¡åä¸æ¥èªä¸åä½ç½®ï¼åå¸ï¼çä¸åæ¶é´åºåç¸å¹é
ï¼è¯¥è¿ç¨å
许æåç¸å
³çæ¶é´æ¨¡å¼ãæåï¼ä»ä»¬è½å¤é对ä¸åçä½ç½®ï¼åå¸ï¼é¢æµéæ±ï¼ä¼äºä¼ ç»çé¢æµæ¹æ³ã
对äºè¿ä¸ªé®é¢ï¼Uber使ç¨äºä»ä»¬çå
é¨æ°æ®ï¼å³ä¸ååå¸çåºè¡æ°æ®ï¼å
¶å
å«äºä¸äºé¢å¤ç¹å¾ï¼å¤©æ°ä¿¡æ¯ãåå¸ç级信æ¯ãä»ä»¬çç®æ æ¯ä»¥åºå®çªå£æ°æ®ï¼å³è¿å»ä¸å¤©ï¼é¢æµç¬¬äºå¤©çéæ±ã
ä¸å¹¸çæ¯ï¼æ们并没æè¿ç§ä¼è´¨çæ°æ®ï¼ä¸è¿å¹¸å¥½æ们å¯ç±çkaggleç²ä¸ç»ææéäºä¸ä¸ªä¼è´¨çæ°æ®éï¼Avocado Prices Dataset ï¼https://www.kaggle.com/neuromusic/avocado-pricesï¼ãè¿ä¸ªæ°æ®å±ç¤ºäºä¸¤ç§ä¸ååç§çé³æ¢¨çåå²ä»·æ ¼ï¼åå
¶å¨ç¾å½å¤ä¸ªååºçééã
æ们éæ©è¿ä¸ªæ°æ®ä¸»è¦æ¯å 为æ们éè¦å
·ææ¶é´ä¾èµæ§çåµå¥æ°æ®éï¼æ们æ¥æä¸å
±54个ååºçé³æ¢¨éå®è®°å½ï¼ä¹å°±æ¯æ们æ说çæ¶é´åºåæ°æ®ï¼å¦æç®ä¸ä¸åç§ç±»ï¼å¸¸è§åææºï¼ï¼æ们就æ108个æ¶é´åºåãUberçç§ç 人å强è°è¿ç§æ°æ®ç»æé常éè¦ï¼å 为å®å¯ä»¥è®©æ们ç模ååç°å
¶ä¸éè¦çéèå
³ç³»ãå¨æ们使ç¨LSTM Autoencoderåç¹å¾æåçæ¶åï¼åºåé´çå
³ç³»ä¹ä¼ä¸ºæ们模åçææ带æ¥æåã
æ们使ç¨äºä»å¼å§å°2017å¹´æ«ä¸ºæ¢çå®ä»·æ°æ®æ建模åï¼è18å¹´æå¼å§ä¸¤æçæ°æ®æ们æ¿æ¥åæµè¯æ°æ®ãæ们åææ¶ï¼åºè¯¥èèå°æææ°æ®çåå½æ²çº¿ï¼å¾ä¸æ¾ç¤ºçé¢çè¾å¼±ï¼æ以æ们å³å®ï¼ç»å®ä¸ä¸ªåºå®ççªå£ï¼å³è¿å»åå¨æ°æ®ä½ä¸ºè®ç»éï¼é¢æµå³å°å°æ¥çä»·æ ¼ã
è®ç»æ°æ®ï¼èè²ï¼æµè¯æ°æ®ï¼æ©è²ï¼ï¼åæ¬æææ°æ®
ç±äºç¼ºä¹ææ°å¢é¿å交æè¡ä¸ºï¼æ们ä¸éè¦æ©å±æ们çä»·æ ¼åºåã
模å
为äºè§£å³æ们çé¢æµä»»å¡ï¼æ们å¤å¶äºUberçä¸ä¸ªæ°ç»æ模åï¼å®æ¶ä¸ä¸ªä½æ¨¡åå´ä¸ºæ们æä¾äºå¤æçé¢æµåè½ãå¦ä¸å¾æ示ï¼æ们è®ç»LSTM Autoencoderä½ä¸ºæ们模åç第ä¸é¨åï¼èªå¨ç¹å¾æåï¼è¿å¯¹äºå¤§éæè·å¤æçå¨ææ¶é´åºåæ¯å¾éè¦çãç¹å¾åééè¿æ¼æ¥åä½ä¸ºæ°çè¾å
¥ä¼ å°LSTM Forecaster模åä¸åé¢æµ(autoencoder模åè¾å
¥çæ¯å¤ä¸ªæ¶é´åºåï¼è¿éæ¯æ¼æ¥å¥½çåä¸åéï¼ã
æ们çforecaster模åçå·¥ä½æµç¨åå好ç解ï¼æ们æä¸ä¸ªåå§ççªå£ï¼ä»£è¡¨çä¸åååºçè¥å¹²å¨å®ä»·æ°æ®ãæ们é¦å
使ç¨è¿äºæ°æ®å»è®ç»æ们LSTM Autoencoderï¼ä¹åå é¤encoder模åï¼å¹¶å©ç¨å®å¶ä½ç¹å¾çæå¨ï¼æååå»è®ç»æ们forecaster模åä¸çLSTM 模ååé¢æµä»»å¡ãåºäºçå®/åå¨çåå½å¼å人é åéæ们å¯ä»¥è·å¾çä¸å¨çé³æ¢¨é¢æµä»·æ ¼ã
å¾çæ¥èªäºTime-series ExtremeEvent Forecasting with Neural Networks atâUber
æ们å¯ä»¥å¾å®¹æå°å¨keraså®ç°è¿ä¸ªé»è¾ã
æ们çLSTMAutoencoders模åç±ç®åçLSTM encoderå±ç»æï¼å
¶ä½åç±LSTM decoderç»æï¼æåè¿æä¸å±TImeDistributeå±ï¼åè«å¿äºãä½ å°ç¥éå¨æ¨¡åéªè¯æ¶æ·»å dropoutç好å¤ï¼ç¸ä¿¡æï¼ä¸ä¼å®³ä½ çã
input_ae= Input(shape = (sequence_length, 1))
encode_ae = LSTM(128, return_sequences = True, dropout = 0.3)(input_ae, training = True)
decode_ae = LSTM(32, return_sequences = True, dropout = 0.3)(encode_ae, training = True)
out_ae = TimeDistributed(Dense(1))(decode_ae)
sequence_autoencoder = Model(input_ae, out_ae)
sequence_autoencoder.compile(optimizer='adam', loss='mse', metrics=['mse'])
sequence_autoencoder.fit(X, y, batch_size = 16, epochs = 100, verbose = 2, shuffle=True)
æ们ä¼å°ç¹å¾æåé¨å计ç®åºæ¥å¹¶æ¼æ¥ä½ä¸ºå
¶ä»åéãå
³äºè¿ç¹æåUberç解å³æ¹æ¡æç¹åå·®ï¼ä»ä»¬å»ºè®®ä½¿ç¨æ´åææ¯ï¼ä¾å¦å¹³åï¼å°ç¹å¾åéèåï¼ä½ä¸ºæ们ç¹å¾åéçæåæä½ãæå³å®è®©å®ä»¬ä¿æåæ ·ï¼å 为å¨æçå®éªä¸è¿æ ·å¯ä»¥ç»æ带æ¥æ´å¥½çç»æã
encoder = Model(input_ae, encode_ae)
XXÂ =Â encoder.predict(X)
XXF = np.concatenate([XX, F], axis = 2)
æåï¼é¢æµæ¨¡åæ¯å¦ä¸ä¸ªåºäºç®åLSTMçç¥ç»ç½ç»ã
inputs1 = Input(X_train1.shapw[1], X_train1.shape[2])
lstm1 = LSMT(128, return_sequence=True, dropout = 0.3)(inputs1, training = True)
lstm1 = LSTM(32, return_sequence=True, dropout = 0.3)(lstm1, training = True)
dense1Â =Â Dense(50)(lstm1)
out1 = Dense(1)(dense1)
model1 = Model(inputs, out1)
model1.compile(loss='mse', optimizer='adam', metrics=['mse'])
model.fit(X_train1, y_train1, epochs=30, batch_size=128, verbose=2, sh
æåï¼æ们已ç»åå¤å¥½çä¸äºç»æååé¢æµãæåä¸æ¥æè¦åçæ¯ï¼ä¸ºäºè¿è¡ç»æ对æ¯ï¼æ们éè¦å建ä¸ä¸ªå¯¹æ模åï¼å¶é åºä¸äºå
·æå¥å£®æ§é¢æµæ¹æ³çç»æã
个人æ¥çï¼è¯ä¼°ä¸¤ä¸ªä¸åç¨åºçæ好æ¹æ³æ¯å°½å¯è½å¤çéå¤èªèº«ï¼ä¸ºäºè½å¤è®©å®ä»¬è½å¤èç¦å¨çæ£éè¦å
³æ³¨çç¹ä¸ãå¨è¿æ¬¡å®è·µä¸ï¼ææ³å±ç¤ºä¸äºLSTMèªç¼ç è½å¤ä½ä¸ºä¸ä¸ªæåçå·¥å
·ï¼äº§åºå¯¹æ¶åºæ°æ®é¢æµæå©çç¸å
³ç¹å¾çè¯æ®ãå¨è¿ç§å±é¢ä¸å»è¯ä¼°æ们æ¹æ³ç好å¤ï¼æå³å®å»å¼åä¸ä¸ªæ°çé¢æµä»·æ ¼ç模åï¼ç¨ä¹åé¢æµNNåæ ·çç»æã
模å1 å模å2 ä¹é´ä¸åç¹å¨äºï¼å®ä»¬æ¥æ¶å°çç¹å¾ä¸ä¸æ ·ï¼
模å1æ¥æ¶ç¼ç å¨è¾åºå ä¸åå½ç»æï¼
模å2æ¥æ¶åå²åå§æ°æ®å ä¸åå½ç»æã
ä¸ç¡®å®æ§ä¼°è®¡
å¨èªç¶ä¸å¯¹äºäºå
³å©ççæ端äºä»¶æ¶åºé¢æµæ¯é常éè¦çãå¦å¤ï¼å¦æä½ å°è¯å建ä¸ä¸ªåºäºç¥ç»ç½ç»ç模åï¼ä½ çç»æä¹å°ä¼åå¶äºç¥ç»ç½ç»åå§æéåå§åï¼ä¸ºäºå
æè¿ä¸ªç¼ºç¹ï¼æä¸äºç°åçæ¹æ³æ¥åºå¯¹ä¸ç¡®å®æ§ä¼°è®¡ï¼ä»è´å¶æ¯å°åºäºbootstrapç论ã
å¨Uberç 究åçå·¥ä½ä¸ï¼ä»ä»¬èåæ¥bootstrapåè´å¶æ¯æ¹æ³æ¥å建ä¸ä¸ªç®åãå¥å£®ãæç¡®å®ä¾¿æ·çã并ä¸ææ¶æç模åã
è¿é¡¹ææ¯æ¯é常ç®å并ä¸å®ç¨ï¼æ们已ç»é¨ç½²ä¸æ¥ãå¦ä¸å¾æ示ï¼å¨ç¥ç»ç½ç»åé¦è¿ç¨ä¸ï¼dropoutåºç¨å¨æ¯ä¸å±ä¸ï¼å
æ¬ç¼ç å±åé¢æµç½ç»ãç»æï¼ç¼ç å±éæºdropoutè½å¤å¨åµå
¥ç©ºé´æ´èªæçè¾å
¥ï¼è®©æ¨¡åæ³åè½åå¢å¼ºï¼èä¸ä¼ ææ´è¿éè¿é¢æµç½ç»ã
å¾pythonç说ï¼å¨ç¥ç»ç½ç»ä¸æ们ç®åå¢å ä¸äºå¯è®ç»çdropoutå±ï¼å¨é¢æµä¸æ们æ¿æ´»å®ä»¬ï¼kerasé¢æµä¸å»é¤æ¥dropoutï¼ï¼ä¸è¾¹æ¯æç¨è¿çä¸äºç®ååè½ï¼ç®å为ï¼dropout æ¿æ´»ï¼ç¹å¾ä¸²èï¼é¢æµææçæ°æ®ã
为äºæåçè¯ä¼°ï¼æ们å¿
é¡»è¿ä»£è°ç¨ä¸è¾¹çå½æ°ï¼åå¨å®ä»¬çç»æãæä¹å¯ä»¥è®¡ç®åºå¨æ¯ä¸æ¬¡è¿ä»£ä¸çé¢æµåå¼ï¼æéæ©çæ¯åç»å¯¹å¼è¯¯å·®ï¼ã
scores1Â =Â []
for i in tqdm.tqdm(range(0,100)):
  scores1.append(mean_absolute_error(stoc_drop1(0.5), y_test1))
print(np.mean(scores1), np.std(scores1))
æ们å¿
须设置è¶
åæ°ï¼å°±æ¯è¿ä»£æ¬¡æ°ï¼dropoutæ¯çãåå¨æ¯ä¸æ¬¡é¢æµåå¼ä¹åï¼æ们å¯ä»¥è®¡ç®åå¼ï¼æ åå·®ï¼ä»¥åç¸å
³åæ¹ç»å¯¹å¼è¯¯å·®ã
é¢æµåç»æ
æ们对æ们çâç«äºæ¨¡åâå¤å¶äºåæ ·çè¿ç¨ï¼åªä½¿ç¨lstmé¢æµç½ç»ãå¨å¹³åå¾åå计ç®ä¸ç¡®å®åº¦åï¼æç»ç»æ为ï¼LSTMèªå¨ç¼ç å¨+LSTMé¢æ¥å0.118 Maeï¼0.0012 Maeä¸ç¡®å®åº¦ï¼ï¼å个LSTMé¢æ¥å0.124 Maeï¼0.0015 Maeä¸ç¡®å®åº¦ï¼ãå¨ä¸ç¡®å®æ§ç¨åº¦ç¸åçæ
åµä¸ï¼æ们çé¢æµç²¾åº¦æç»æé«äº5%ãæ们å¯ä»¥æè¨ï¼æ们çlstmèªå¨ç¼ç å¨æ¯ä¸ä¸ªä»æ¶é´åºåä¸æåéè¦çæªç¥ç¹å¾ç好æ¦å¨ãä¸é¢æè¿æ¥åäºææºé³æ¢¨åä¼ ç»é³æ¢¨å¨åä¸å¸åºä¸çå¾å表ç°ã
æµè¯æ°æ®çæ§è½ï¼maeï¼æ¯è¾
å¨è®ç»æé´ï¼æä¹ä¿çæé¤æ´ä¸ªå¸åºï¼å¥¥å°å·´å°¼å°åºï¼çæå©ãè¿æ¯å 为ææ³æµè¯æ们çç½ç»å¨æ²¡æè®ç»è¿çæ°æ®ä¸çææãæ们å¨ææºå¸åºåä¼ ç»å¸åºç表ç°é½æææ¹åã
çä¸è§æ¶é´åºåçæ§è½æ¯è¾
æ»ç»
å¨æ¬æä¸ï¼æå¤å¶äºUber为ç¹æ®äºä»¶é¢æµå¼åç端å°ç«¯ç¥ç»ç½ç»æ¶æãææ³å¼ºè°çæ¯ï¼lstmèªå¨ç¼ç å¨å¨ç¹å¾æåä¸çä½ç¨ï¼è¯¥æ¹æ¡çå¯æ©å±æ§ï¼è½å¤å¾å¥½å°æ¨å¹¿ï¼é¿å
äºä¸ºæ¯ä¸ªæ¶é´åºåè®ç»å¤ä¸ªæ¨¡åï¼è½å¤ä¸ºç¥ç»ç½ç»çè¯ä»·æä¾ä¸ç§ç¨³å®èæççæ¹æ³ã
æè¿æ³¨æå°ï¼å½ä½ æ足å¤æ°éçæ¶é´åºåå
±äº«å
±åçè¡ä¸ºæ¶ï¼è¿ç§è§£å³æ¹æ¡é常éåâ¦â¦è¿äºè¡ä¸ºä¸æ¯æ¾èæè§çéè¦ï¼èæ¯èªå¨ç¼ç å¨ä¸ºæ们å¶é çã
[1] Deep and Confident Prediction for Time Series atUber: Lingxue Zhu, Nikolay Laptev
[2] Time-series ExtremeEvent Forecasting with Neural Networks at Uber: Nikolay Laptev, Jason Yosinski,Li Erran Li, Slawek Smyl
via https://towardsdatascience.com/extreme-event-forecasting-with-lstm-autoencoders-297492485037
å¯ä»¥å¨
æ¬
å
¬ä¼å·åå°
åå¤å
³é®è¯ï¼â
æ端
âè·åæ¬æç« ç示ä¾ä»£ç é¾æ¥ï¼å¦æè§å¾æç¨ï¼Â 请å¿åå¬ä½ ççè¨åèµå¦ï¼~
ââ å® ââ