Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么SARIMA的准确度会提高?_Python_Machine Learning_Graph_Prediction_Arima - Fatal编程技术网

Python 为什么SARIMA的准确度会提高?

Python 为什么SARIMA的准确度会提高?,python,machine-learning,graph,prediction,arima,Python,Machine Learning,Graph,Prediction,Arima,我正试图找到ARIMA和SARIMA。 我有一批在海边卖的三明治 上图中显示的是我的数据+我用来使其静止的差分 smodel = auto_arima(train, start_p=1, start_q=1, test='adf', max_p=3, max_q=3, m=12, start_P=0, seasonal=True,

我正试图找到ARIMA和SARIMA。 我有一批在海边卖的三明治

上图中显示的是我的数据+我用来使其静止的差分

smodel = auto_arima(train, start_p=1, start_q=1,
                     test='adf',
                     max_p=3, max_q=3, m=12,
                     start_P=0, seasonal=True,
                     d=None, D=1, trace=True,
                     error_action='ignore',  
                     suppress_warnings=True, 
                     stepwise=True)
上面我使用auto_arima来适应我的模型

  n_periods = 6
fitted, confint = smodel.predict(n_periods=n_periods, return_conf_int=True)
index_of_fc = pd.date_range(train.index[-1], periods = n_periods, freq='MS')

# make series for plotting purpose
fitted_series = pd.Series(fitted, index=index_of_fc)
lower_series = pd.Series(confint[:, 0], index=index_of_fc)
upper_series = pd.Series(confint[:, 1], index=index_of_fc)

# Plot
plt.plot(train)
plt.plot(fitted_series, color='darkgreen')
plt.fill_between(lower_series.index, 
                 lower_series, 
                 upper_series, 
                 color='k', alpha=.15)

plt.title("SARIMA - Final Forecast")
plt.show()
在这里,我绘制了我的列车数据+我的预测,这给了我以下结果(我仍然不知道为什么它在图表中跳过了一个月,但数字是正确的):

最后,我会这样测试我的准确性:

  # Accuracy metrics
def forecast_accuracy(forecast, actual):
    mape = np.mean(np.abs(forecast - actual)/np.abs(actual))  # MAPE
    me = np.mean(forecast - actual)             # ME
    mae = np.mean(np.abs(forecast - actual))    # MAE
    mpe = np.mean((forecast - actual)/actual)   # MPE
    rmse = np.mean((forecast - actual)**2)**.5  # RMSE
    corr = np.corrcoef(forecast, actual)[0,1]   # corr
    mins = np.amin(np.hstack([forecast[:,None], 
                              actual[:,None]]), axis=1)
    maxs = np.amax(np.hstack([forecast[:,None], 
                              actual[:,None]]), axis=1)
    minmax = 1 - np.mean(mins/maxs)             # minmax
    acf1 = acf(fitted-test)[1]                      # ACF1
    return({'mape':mape, 'me':me, 'mae': mae, 
            'mpe': mpe, 'rmse':rmse, 'acf1':acf1, 
            'corr':corr, 'minmax':minmax})

forecast_accuracy(fitted, test.values)
这是我的结果:

{'mape': 0.03461030567300854,
 'me': 6.729205725022392,
 'mae': 17.97150355923618,
 'mpe': 0.016813031496317913,
 'rmse': 20.42619043264491,
 'acf1': -0.13837977897549658,
 'corr': 0.9789628479818636,
 'minmax': 0.033630138432890866}
现在,如果我错了,请纠正我,但这里的MAPE显示为0.034,基本上说我的预测准确率约为96.6%

我已经在不同的时间段(预测3个月前和5个月)测试了这一点,但我无法理解的是,5个月的准确度高于3个月。因为这对我来说很奇怪,我真的很想知道你们是否有人对此有解释。也许我的模型不正确?我只是从ARIMA开始,我的理论是,自动ARIMA不会改变数据,仍然存在趋势,但这只是一个猜测,我不知道如何实现

非常感谢您的帮助

(哦,如果有人知道为什么我的图表跳过了1个月,请让我也知道!我知道它与以下行有关,但我不知道如何绘制它)

index_of_fc = pd.date_range(train.index[-1], periods = n_periods, freq='MS')