1. 程式人生 > >Kaggle Learn Time Series Modeling 學習小計

Kaggle Learn Time Series Modeling 學習小計

 

ARIMA模型,引數含義參考:https://www.cnblogs.com/bradleon/p/6827109.html

from statsmodels.tsa.arima_model import ARIMA
plt.figure(figsize = (15,8))
model = ARIMA(Train_log, order = (2,1,0))  #here q value is zero since it is just AR Model

 

SARIMAX Model,多元季節性時間序列模型,用於預測與異常診斷,參考部落格:https://blog.csdn.net/weixin_41512727/article/details/82999831

import statsmodels.api as sm
y_hat_avg = valid.copy()
fit1 = sm.tsa.statespace.SARIMAX(Train.Count, order = (2,1,4), seasonal_order =(0,1,1,7)).fit()
y_hat_avg['SARIMA'] = fit1.predict(start="2014-6-25", end="2014-9-25", dynamic=True)

 

LSTM Model

import numpy as np
from numpy import newaxis
from keras.layers.core import Dense, Activation, Dropout from keras.layers.recurrent import LSTM from keras.models import Sequential my_model = Sequential() my_model.add(LSTM( input_shape=(None, 1), units=50, return_sequences=True)) my_model.add(LSTM(100, return_sequences=False)) my_model.add(Dropout(
0.5)) my_model.add(Dense(1)) my_model.add(Activation('linear')) my_model.compile(loss='mse', optimizer='rmsprop') # Fill in the parameters to fit your model my_model.fit( X_train, y_train, batch_size=1024, # Fill this in epochs=1, # Fill this in validation_split=0.05)