Python Statsmodels get_prediction( ), 'ValueError: Got a string for start and dates is None'
Python Statsmodels get_prediction( ), 'ValueError: Got a string for start and dates is None'
我从一个较大的数据帧中提取了以下时间序列数据帧。
df_test = df.loc[(df['time'] >= '2015-05-01') & (df['time'] <= '2015-05-09')]
df_test.set_index('time')
数据的头部是这样的:
time total_consumption
122400 2015-05-01 00:01:00 106.391
122401 2015-05-01 00:11:00 120.371
122402 2015-05-01 00:21:00 109.292
122403 2015-05-01 00:31:00 99.838
122404 2015-05-01 00:41:00 97.387
使用SARIMAX,我得到了这个模型:
mod = sm.tsa.statespace.SARIMAX(np.asarray(df_test['total_consumption']),
order=(1,1,1),
seasonal_order=(0,1,1,12),
enforce_stationarity=False,
enforce_invertibility=False)
results_final = mod.fit()
然后我尝试根据模型进行预测:
start = pd.to_datetime('2015-05-08 00:01:00')
pred = results_final.get_prediction(start, dynamic=False)
pred_ci = pred.conf_int()
但是,当我尝试使用 get_prediction() 命令预测数据帧的结尾时,我收到此错误消息并且似乎无法弄清楚原因。
ValueError: Got a string for start and dates is None
谢谢
我想问题是你没有使用时间索引。如果要使用日期,则数据需要是具有 date/time 索引的 pandas 系列。
在创建模型时删除 np.asarray 并直接使用 df_test['total_consumption'] 后尝试。
numpy 数组没有任何日期信息,因此不能使用日期来指定预测期。在使用 numpy 数组的情况下,需要使用通常的 numpy 整数索引指定预测或预测周期。
我从一个较大的数据帧中提取了以下时间序列数据帧。
df_test = df.loc[(df['time'] >= '2015-05-01') & (df['time'] <= '2015-05-09')]
df_test.set_index('time')
数据的头部是这样的:
time total_consumption
122400 2015-05-01 00:01:00 106.391
122401 2015-05-01 00:11:00 120.371
122402 2015-05-01 00:21:00 109.292
122403 2015-05-01 00:31:00 99.838
122404 2015-05-01 00:41:00 97.387
使用SARIMAX,我得到了这个模型:
mod = sm.tsa.statespace.SARIMAX(np.asarray(df_test['total_consumption']),
order=(1,1,1),
seasonal_order=(0,1,1,12),
enforce_stationarity=False,
enforce_invertibility=False)
results_final = mod.fit()
然后我尝试根据模型进行预测:
start = pd.to_datetime('2015-05-08 00:01:00')
pred = results_final.get_prediction(start, dynamic=False)
pred_ci = pred.conf_int()
但是,当我尝试使用 get_prediction() 命令预测数据帧的结尾时,我收到此错误消息并且似乎无法弄清楚原因。
ValueError: Got a string for start and dates is None
谢谢
我想问题是你没有使用时间索引。如果要使用日期,则数据需要是具有 date/time 索引的 pandas 系列。 在创建模型时删除 np.asarray 并直接使用 df_test['total_consumption'] 后尝试。
numpy 数组没有任何日期信息,因此不能使用日期来指定预测期。在使用 numpy 数组的情况下,需要使用通常的 numpy 整数索引指定预测或预测周期。