簡體   English   中英

高錯誤 ARIMA model - 計數並繼續值 - Python

[英]High error ARIMA model -count and continues values - Python

我有一個時間序列數據。 它有每日頻率。

我想用 ARIMA model 預測下周或下個月的數據。

在此處輸入圖像描述

這是我的時間序列數據的圖表:

在此處輸入圖像描述

首先,我使用stats model 中的方法seasonal_decompose 來檢查趨勢/會話性/殘差,如下所示:

from statsmodels.tsa.seasonal import seasonal_decompose
result = seasonal_decompose(df['n_transactions'], model='add')
result.plot(); 

在此處輸入圖像描述

我檢查我的數據是否是固定的:

from statsmodels.tsa.stattools import adfuller

def adf_test(series,title=''):
    """
    Pass in a time series and an optional title, returns an ADF report
    """
    print(f'Augmented Dickey-Fuller Test: {title}')
    result = adfuller(series.dropna(),autolag='AIC') # .dropna() handles differenced data

    labels = ['ADF test statistic','p-value','# lags used','# observations']
    out = pd.Series(result[0:4],index=labels)

    for key,val in result[4].items():
        out[f'critical value ({key})']=val

    print(out.to_string())          # .to_string() removes the line "dtype: float64"

    if result[1] <= 0.05:
        print("Strong evidence against the null hypothesis")
        print("Reject the null hypothesis")
        print("Data has no unit root and is stationary")
    else:
        print("Weak evidence against the null hypothesis")
        print("Fail to reject the null hypothesis")
        print("Data has a unit root and is non-stationary")

adf_test(df['n_transactions'])

Augmented Dickey-Fuller Test: 
ADF test statistic       -3.857922
p-value                   0.002367
# lags used              12.000000
# observations          737.000000
critical value (1%)      -3.439254
critical value (5%)      -2.865470
critical value (10%)     -2.568863
Strong evidence against the null hypothesis
Reject the null hypothesis
Data has no unit root and is stationary

我使用 auto_arima 來獲得 model 的最佳參數:

from pmdarima import auto_arima      
auto_arima(df['n_transactions'],seasonal=True, m = 7).summary()

在此處輸入圖像描述

我用這個參數訓練我的 model:

train = df.loc[:'2020-05-12']
test = df.loc['2020-05-13':]

model = SARIMAX(train['n_transactions'],order=(1, 1, 1))
results = model.fit()
results.summary()

我計算預測:

start=len(train)
end=len(train)+len(test)-1
predictions = results.predict(start=start, end=end, dynamic=False, typ='levels').rename('SARIMA(0,1,3)(1,0,1,12) Predictions')


ax = test['n_transactions'].plot(legend=True,figsize=(12,6),title=title)
predictions.plot(legend=True)
ax.autoscale(axis='x',tight=True)
ax.set(xlabel=xlabel, ylabel=ylabel);

在此處輸入圖像描述

但是model卻不能取得好的效果,為什么?

編輯

正如您建議的那樣,我使用而不是計算我為此獲得的收入,這可能是問題所在:

在此處輸入圖像描述

在此處輸入圖像描述

在此處輸入圖像描述

但是 model 並沒有獲得好的結果:

在此處輸入圖像描述

我可以從這里得出什么結論?

您的數據(無論是計數還是收入)都不太適合 SARIMAX model,原因如下:

  • 不能為負
  • 它有大量完全等於零的值
  • 它的波動性隨着時間而變化(這是異方差)

相比之下,SARIMAX model 具有同方差高斯誤差,不滿足任何這些特征。 因此,SARIMAX 模型的預測不會很好。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM