【问题标题】:High error ARIMA model -count and continues values - Python高错误 ARIMA 模型 - 计数和继续值 - Python
【发布时间】:2020-09-10 09:43:07
【问题描述】:

我有一个时间序列数据。它有每天的频率。

我想使用 ARIMA 模型预测下一周或下个月的数据。

这是我的时间序列数据图表:

首先我使用stats模型中的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 来获得模型的最佳参数:

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

我用这个参数训练我的模型:

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);

但是模型不能得到好的结果,为什么?

编辑

我已经使用而不是计算我为此获得的收入,因为你建议我这可能是问题所在:

但是模型并没有获得好的结果:

我可以从这里得出什么结论?

【问题讨论】:

    标签: python statsmodels arima


    【解决方案1】:

    您的数据(无论是计数还是收入)都不太适合 SARIMAX 模型,原因如下:

    • 不能为负数
    • 它有大量完全等于零的值
    • 其波动性随时间而变化(这是异方差)

    相比之下,SARIMAX 模型具有同方差高斯误差,不满足任何这些特征。因此,SARIMAX 模型的预测不会很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-11-15
      • 2020-09-09
      • 2017-02-10
      • 2016-06-06
      • 1970-01-01
      • 2020-09-26
      • 1970-01-01
      相关资源
      最近更新 更多