【问题标题】:converting back prediction values to original scale(forecasting with python arima model)将预测值转换回原始比例(使用 python arima 模型进行预测)
【发布时间】:2020-02-16 10:48:33
【问题描述】:

我正在尝试使用 ARIMA 模型进行一些预测。我在将预测转换回原始比例时遇到问题。这是我的代码。 有人可以帮我找到脚本中的错误吗?非常感谢,谢谢。

from statsmodels.tsa.arima_model import ARIMA

#arima model
model=ARIMA(ts_logscale,order=(2,1,2))
results_ARIMA=model.fit(disp=-1)
plt.plot(datasetlogdiffshifting)
plt.plot(results_ARIMA.fittedvalues,color='red')
plt.title('RSS: %.4f'% sum((results_ARIMA.fittedvalues-datasetlogdiffshifting["Chargé (T)"])**2))
print('plotting ARIMA model')

现在,当我尝试转换回来时:

#converting back
#creating a time serie
predictions_ARIMA_diff=pd.Series(results_ARIMA.fittedvalues,copy=True)
#convert to cumulative sum
predictions_ARIMA_diff_cumsum=predictions_ARIMA_diff.cumsum()

predictions_ARIMA_log=pd.Series(ts_logscale['Chargé (T)'].ix[0],index=ts_logscale.index)
predictions_ARIMA_log=(predictions_ARIMA_log).add(predictions_ARIMA_diff_cumsum,fill_value=0)
#plotting
predictions_ARIMA=np.exp(predictions_ARIMA_log)
plt.plot(ts,color='blue')
plt.plot(predictions_ARIMA,color='red')

你可以看到它与第一个情节非常不同......

【问题讨论】:

    标签: python machine-learning prediction forecasting arima


    【解决方案1】:

    ARIMA (2,1,2):是具有两 (2) 个自回归项、一 (1) 个后移运算符和两 (2) 个移动平均项的模型。现在,当您应用一 (1) 个后移运算符时,您不必担心,因为 statsmodels 模型会转换回您的预测,因此,这里唯一的问题是您之前所做的日志转换,为此,只需使用 np.exp你的预测和解决的问题!

    【讨论】:

    • 我试过这个 predictions=np.exp(results_ARIMA.fittedvalues) 但它比以前更糟
    • @OumaymaRiahi 您必须考虑到,当您使用 results_ARIMA.fittedvalues 时,已经取出了后移运算符,所以现在剩下的唯一转换是对数转换。也就是说,要将对数转换为正常值,您应该应用 np.exp。您如何知道 ARIMA(2,1,2) 非常适合您的数据?
    • 我绘制了 ACF 和 PACF
    • @OumaymaRiahi ACF 和 PACF 用于日志转换数据还是原始数据?
    • @Snedecor AR 和 MA 术语都可以用 backshift 运算符来编写,因此您对 ARIMA(2,1,2) 模型的描述(尤其是关于 d 的部分)参数)有点令人困惑。 ARIMA(2,1,2) 是一个具有 2 个 AR 项、1 个差分阶和 2 个 MA 项的模型。
    猜你喜欢
    • 2023-03-11
    • 1970-01-01
    • 2021-11-04
    • 2016-06-06
    • 2019-05-06
    • 2023-03-30
    • 1970-01-01
    • 2016-06-02
    • 2020-04-07
    相关资源
    最近更新 更多