我正在使用ARIMA模型来预测产品的销售量。数据位于2015年1月1日至2016年11月24日的csv文件中,间隔为1周。我正在尝试预测9步,即未来9周。
CSV中的数据:
"01-01-2015",9
"08-01-2015",8
"15-01-2015",13
"22-01-2015",10
"29-01-2015",12
"05-02-2015",5
"12-02-2015",4
"19-02-2015",6
"26-02-2015",9
"05-03-2015",3
"12-03-2015",3
"19-03-2015",2
...
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的代码:
def parser(x):
return datetime.datetime.strptime(x, '%d-%m-%Y')
fn = 'filename.csv'
y = pd.read_csv(fn, header = 0, parse_dates = [0], index_col = 0, squeeze = True, date_parser = parser)
newmod = sm.tsa.statespace.SARIMAX(y,order=(1, 1, 0),seasonal_order=(1, 1, 0, 12),enforce_stationarity=False,enforce_invertibility=False)
newresults = newmod.fit()
pred_uc = newresults.get_forecast(steps = 9)
pred_ci = pred_uc.conf_int()
y1 = pred_ci.iloc[:,0]
y2 = pred_ci.iloc[:,1]
ax = y.plot(label = "observed")
pred_uc.predicted_mean.plot(ax=ax, label='Forecast')
ax.fill_between(pred_ci.index, pred_ci.iloc[:,0],pred_ci.iloc[:,1], color = 'k' , …Run Code Online (Sandbox Code Playgroud)