【機器學(xué)習(xí)】NeuralProphet,這個時序工具包也太強了吧...
NeuralProphet

幾乎絕大多數(shù)做時間序列的朋友都了解Facebook的Prophet模型,因為其在準(zhǔn)確性、可解釋性等方面有著良好的性能,而且可以為用戶自動化許多元素(如超參數(shù)選擇或特征工程),因而它獲得了廣泛的應(yīng)用。本文我們介紹一個最新的NeuralProphet時,從名字就可以看出,這個是神經(jīng)網(wǎng)絡(luò)和Prophet的結(jié)合,與傳統(tǒng)的黑盒NN不同,本文我們就介紹的NeuralProphet模型集成了Prophet的所有優(yōu)點,不僅具有不錯的可解釋性,還有優(yōu)于Prophet的預(yù)測性能。

Prophet
Prophet如果認(rèn)為是基本自回歸的擴展(除了使用lagged的目標(biāo)值,還對輸入變量使用傅立葉變換,這使得我們可以通過調(diào)模型拿到更好的結(jié)果)。
Prophet可以使用額外的信息,不僅僅是target的延遲值; 模型能融入節(jié)假日信息; 可以自動檢測趨勢的變化;
NeuralProphet
和許多黑盒子的NN不同,NeuralProphet保留了Prophet的所有優(yōu)勢,同時,通過引入改進的后端(Pytorch代替Stan)和使用自回歸網(wǎng)絡(luò)(AR網(wǎng)絡(luò)),將神經(jīng)網(wǎng)絡(luò)的可擴展性與AR模型的可解釋性結(jié)合起來,提高其準(zhǔn)確性和可擴展性。
AR網(wǎng)絡(luò)——它是一個單層網(wǎng)絡(luò),經(jīng)過訓(xùn)練可以模擬時間序列信號中的AR過程,但規(guī)模比傳統(tǒng)模型大得多。
NeuralProphet VS Prophet
NeuralProphet使用PyTorch的梯度下降進行優(yōu)化,使得建模速度更快; 利用自回歸網(wǎng)絡(luò)對時間序列自相關(guān)進行建模; 滯后回歸器使用單獨的前饋神經(jīng)網(wǎng)絡(luò)建模; NeuralProphet具有可配置的前饋神經(jīng)網(wǎng)絡(luò)的非線性深層; 模型可調(diào)整到特定的預(yù)測范圍(大于1); 提供自定義的損失函數(shù)和度量策略;

1.數(shù)據(jù)讀取
# !pip install neuralprophet
import pandas as pd
from fbprophet import Prophet
from neuralprophet import NeuralProphet
from sklearn.metrics import mean_squared_error
# plotting
import matplotlib.pyplot as plt
# settings
plt.style.use('seaborn')
plt.rcParams["figure.figsize"] = (16, 8)
df = pd.read_csv('./data/wp_log_peyton_manning.csv')
print(f'The dataset contains {len(df)} observations.')
df.head()
The dataset contains 2905 observations.
| ds | y | |
|---|---|---|
| 0 | 2007-12-10 | 9.590761 |
| 1 | 2007-12-11 | 8.519590 |
| 2 | 2007-12-12 | 8.183677 |
| 3 | 2007-12-13 | 8.072467 |
| 4 | 2007-12-14 | 7.893572 |
df.plot(x='ds', y='y', title='Log daily page views');

2.Prophet預(yù)測
test_length = 365
df_train = df.iloc[:-test_length]
df_test = df.iloc[-test_length:]
prophet_model = Prophet()
prophet_model.fit(df_train)
future_df = prophet_model.make_future_dataframe(periods=test_length)
preds_df_1 = prophet_model.predict(future_df)
prophet_model.plot_components(preds_df_1);
prophet_model.plot(preds_df_1);
3. NeuralProphet
nprophet_model = NeuralProphet()
metrics = nprophet_model.fit(df_train, freq="D")
future_df = nprophet_model.make_future_dataframe(df_train,
periods = test_length,
n_historic_predictions=len(df_train))
preds_df_2 = nprophet_model.predict(future_df)nprophet_model.plot(preds_df_2);

4.效果比較
NeuralProphet的效果比Prophet好了很多。
df_test['prophet'] = preds_df_1.iloc[-test_length:].loc[:, 'yhat']
df_test['neural_prophet'] = preds_df_2.iloc[-test_length:].loc[:, 'yhat1']
df_test.set_index('ds', inplace=True)
print('MSE comparison ----')
print(f"Prophet:\t{mean_squared_error(df_test['y'], preds_df_1.iloc[-test_length:]['yhat']):.4f}")
print(f"NeuralProphet:\t{mean_squared_error(df_test['y'], preds_df_2.iloc[-test_length:]['yhat1']):.4f}")
MSE comparison ----
Prophet: 0.3576
NeuralProphet: 0.3057
NeuralProphet在時間序列預(yù)測的效果上面一般會比Prophet好很多,在遇到時間序列問題的時候強烈建議大家嘗試一下。

https://towardsdatascience.com/facebooks-prophet-deep-learning-neuralprophet-76796aed1d86
往期精彩回顧 本站qq群851320808,加入微信群請掃碼:
評論
圖片
表情
