【发布时间】:2020-05-27 19:47:11
【问题描述】:
我正在尝试根据 2014 年 1 月 1 日 ==> 2020 年 1 月 1 日的 6 年数据集来预测需求。 首先,我尝试按月重新组合需求,因此我最终得到了一个包含 2 列(月和销售额)和 72 行(12 月 * 6 年)的数据集。 P.s:我正在使用 python。
我的第一个问题是:知道我只有 72 行这一事实,是否足以预测明年(2020 年)。
我的第二个问题是,是否有任何模型可以建议我使用并且可以让我获得很好的准确性?
我尝试过结合季节性 (sarimax) 和 LSTM 使用 arima 模型,但它不起作用,我不确定我是否做得对。
我的第三个问题是:python中是否有任何测试可以告诉您是否存在季节性?
#shrink the dataset
dataa=data[(data['Produit']=='ACP NOR/STD')&(data['Région']=='Europe')]
gb2=dataa.groupby(by=[dataa['Mois'].dt.strftime('%Y, %m')])['Chargé (T)'].sum().reset_index()
gb2.Mois=pd.to_datetime(gb2.Mois)
[#create a time serie][2]
series = pd.Series(gb2['Chargé (T)'].values, index=gb2.Mois)
#decompose the dataset to 3 things: trend, seasonality and noise
from pylab import rcParams
import statsmodels.api as sm
rcParams['figure.figsize'] = 18, 8
decomposition = sm.tsa.seasonal_decompose(series, model='additive')
fig = decomposition.plot()
plt.show()
#calculate acf and pacf to know in which order to stop
from statsmodels.graphics.tsaplots import plot_acf
from statsmodels.graphics.tsaplots import plot_pacf
from matplotlib import pyplot
pyplot.figure()
pyplot.subplot(211)
plot_acf(series, ax=pyplot.gca())
pyplot.subplot(212)
plot_pacf(series, ax=pyplot.gca())
pyplot.show()
import itertools
p = d = q = range(0, 5)
pdq = list(itertools.product(p, d, q))
seasonal_pdq = [(x[0], x[1], x[2], 12) for x in list(itertools.product(p, d, q))]
print('Examples of parameter combinations for Seasonal ARIMA...')
print('SARIMAX: {} x {}'.format(pdq[1], seasonal_pdq[1]))
print('SARIMAX: {} x {}'.format(pdq[1], seasonal_pdq[2]))
print('SARIMAX: {} x {}'.format(pdq[2], seasonal_pdq[3]))
print('SARIMAX: {} x {}'.format(pdq[2], seasonal_pdq[4]))
import warnings
warnings.filterwarnings("ignore")
for param in pdq:
for param_seasonal in seasonal_pdq:
try:
mod = sm.tsa.statespace.SARIMAX(series,
order=param,
seasonal_order=param_seasonal,
enforce_stationarity=False,
enforce_invertibility=False)
results = mod.fit()
print('ARIMA{}x{}12 - AIC:{}'.format(param, param_seasonal, results.aic))
except:
continue
mod = sm.tsa.statespace.SARIMAX(series,
order=(0, 1, 2),
seasonal_order=(0, 4, 0, 12),
enforce_stationarity=False,
enforce_invertibility=False)
results = mod.fit()
print(results.summary().tables[1])
results.plot_diagnostics(figsize=(16, 8))
plt.show()
#get predictions
pred = results.get_prediction(start=pd.to_datetime('2019-01-01'), dynamic=False)
pred_ci = pred.conf_int()
ax = series['2014':].plot(label='observed')
pred.predicted_mean.plot(ax=ax, label='One-step ahead Forecast', alpha=.8, figsize=(14, 7))
ax.fill_between(pred_ci.index,
pred_ci.iloc[:, 0],
pred_ci.iloc[:, 1], color='k', alpha=.2)
ax.set_xlabel('Date')
ax.set_ylabel('Chargé (T)')
plt.legend()
plt.show()
预测与现实无关... 我真的很感谢任何人的帮助。
【问题讨论】:
标签: python pandas machine-learning neural-network forecasting