Assigning time series prediction confidence interval array to pandas dataframe (Wrong number of items passed 2, placement implies 1)

Viewed 55

I'm currently trying to fit an time series forecasting model using Auto_ARIMA from pmdarima with forecasted value and prediction confidence interval as output. But when i tried to assign the confidence interval output to pandas dataframe it give me some errors. Here's the code and the error:

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

really appreciate it if someone can help me on this, thank you very much

0 Answers
Related