我目前正在尝试使用来自 pmdarima 的 Auto_ARIMA 来拟合时间序列预测模型,并将预测值和预测置信区间作为输出。但是当我尝试将置信区间输出分配给熊猫数据框时,它给了我一些错误。这是代码和错误:
import numpy as np
import pandas as pd
from pmdarima import auto_arima
model = auto_arima(train,
exogenous=df_train[exogenous_features],
start_p=1, start_q=1, d=n_adf, max_p=5, max_q=5,
trace=True, n_jobs = -1, error_action="ignore", suppress_warnings=True)
model.fit(train,
exogenous=df_train[exogenous_features])
forecast, confint = model.predict(n_periods=len(df_valid),
return_conf_int=True, alpha=0.05,
exogenous=df_valid[exogenous_features])
df_valid["Forecast_ARIMA"] = forecast
df_valid["Upper", "Lower"] = confint
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2897 try:
-> 2898 return self._engine.get_loc(casted_key)
2899 except KeyError as err:
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: ('Upper', 'Lower')
The above exception was the direct cause of the following exception:
KeyError Traceback (most recent call last)
8 frames
KeyError: ('Upper', 'Lower')
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/pandas/core/internals/blocks.py in __init__(self, values, placement, ndim)
129 if self._validate_ndim and self.ndim and len(self.mgr_locs) != len(self.values):
130 raise ValueError(
--> 131 f"Wrong number of items passed {len(self.values)}, "
132 f"placement implies {len(self.mgr_locs)}"
133 )
ValueError: Wrong number of items passed 2, placement implies 1
如果有人可以帮助我,真的很感激,非常感谢