Как исправить statsmodel.tsa.statespace.SARIMAX в Python - PullRequest
0 голосов
/ 28 сентября 2019

Я пытаюсь разместить модель в sm.tsa.statespace.SARIMAX, используя код, представленный ниже.Где мне нужно это исправить?

import statsmodels.api as sm

# ряд концов историй 2016.04.30 23:00 до 2016.05.31 17:00
start_range = '2016-04-30 23:00:00'
end_range = '2016-05-31 17:00:00'
time_range = pd.date_range(start_range, end_range, freq='H')
len(time_range)

forecast_juny = []
R = len(selected_cells)
for cell in tqdm_notebook(selected_cells):
    for time in time_range:
        n_kluster = labels[selected_cells.index(cell)] # номер кластера
        zone = typical_zones[n_kluster] # типичная для кластера ячейка
        param = best_param[zone]

        model_fitted = sm.tsa.statespace.SARIMAX(endog=stand_data_full[cell]
                                                                 [time - relativedelta(hours=60):time + relativedelta(hours=7)], 
                                                exog=stand_data_full[feature_list]
                                                                 [time - relativedelta(hours=60):time + relativedelta(hours=7)], 
                                                order=(param[0], d, param[1]), 
                                                seasonal_order=(param[2], D, param[3], S)).filter(best_stand_model[zone].params)

        predicted_data = model_fitted.predict(time + relativedelta(hours=1), time + relativedelta(hours=6), dynamic=True)
        # обратное преобразование из стандартного
        predicted_data = predicted_data * data_std[cell] + data_mean[cell]
        forecast_juny.append((time, predicted_data))

print('len(forecast_juny):', len(forecast_juny))

Я ожидаю выходной подогнанной модели и выведите «len (forecast_juny): 72930».

Но я получил журнал ошибок, представленный ниже.Я действительно расстроен, почему этот код не работал

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~/anaconda3/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_slice_bound(self, label, side, kind)
   4240             try:
-> 4241                 return self._searchsorted_monotonic(label, side)
   4242             except ValueError:

~/anaconda3/lib/python3.7/site-packages/pandas/core/indexes/base.py in _searchsorted_monotonic(self, label, side)
   4199 
-> 4200         raise ValueError('index must be monotonic increasing or decreasing')
ValueError: index must be monotonic increasing or decreasing

During handling of the above exception, another exception occurred:
KeyError                                  Traceback (most recent call last)
<timed exec> in <module>

~/anaconda3/lib/python3.7/site-packages/pandas/core/series.py in __getitem__(self, key)
    808             key = check_bool_indexer(self.index, key)
--> 810         return self._get_with(key)
    812     def _get_with(self, key):

~/anaconda3/lib/python3.7/site-packages/pandas/core/series.py in _get_with(self, key)
    813         # other: fancy integer or otherwise
    814         if isinstance(key, slice):
--> 815             indexer = self.index._convert_slice_indexer(key, kind='getitem')
    816             return self._get_values(indexer)
    817         elif isinstance(key, ABCDataFrame):

~/anaconda3/lib/python3.7/site-packages/pandas/core/indexes/base.py in _convert_slice_indexer(self, key, kind)
   1749         else:
   1750             try:
-> 1751                 indexer = self.slice_indexer(start, stop, step, kind=kind)
   1752             except Exception:
   1753                 if is_index_slice:

~/anaconda3/lib/python3.7/site-packages/pandas/core/indexes/datetimes.py in slice_indexer(self, start, end, step, kind)
   1704 
   1705         try:
-> 1706             return Index.slice_indexer(self, start, end, step, kind=kind)
   1707         except KeyError:
   1708             # For historical reasons DatetimeIndex by default supports

~/anaconda3/lib/python3.7/site-packages/pandas/core/indexes/base.py in slice_indexer(self, start, end, step, kind)
   4105         """
   4106         start_slice, end_slice = self.slice_locs(start, end, step=step,
-> 4107                                                  kind=kind)
   4109         # return a slice

~/anaconda3/lib/python3.7/site-packages/pandas/core/indexes/base.py in slice_locs(self, start, end, step, kind)
   4312         end_slice = None
   4313         if end is not None:
-> 4314             end_slice = self.get_slice_bound(end, 'right', kind)
   4315         if end_slice is None:
   4316             end_slice = len(self)

~/anaconda3/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_slice_bound(self, label, side, kind)
   4242             except ValueError:
   4243                 # raise the original KeyError
-> 4244                 raise err
   4246         if isinstance(slc, np.ndarray):

~/anaconda3/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_slice_bound(self, label, side, kind)
   4236         # we need to look up the label
   4237         try:
-> 4238             slc = self._get_loc_only_exact_matches(label)
   4239         except KeyError as err:
   4240             try:

~/anaconda3/lib/python3.7/site-packages/pandas/core/indexes/base.py in _get_loc_only_exact_matches(self, key)
   4205         get_slice_bound.
   4206         """
-> 4207         return self.get_loc(key)
   4209     def get_slice_bound(self, label, side, kind):

~/anaconda3/lib/python3.7/site-packages/pandas/core/indexes/datetimes.py in get_loc(self, key, method, tolerance)
   1602             # needed to localize naive datetimes
   1603             key = Timestamp(key, tz=self.tz)
-> 1604             return Index.get_loc(self, key, method, tolerance)
   1606         if isinstance(key, time):

~/anaconda3/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   3078                 return self._engine.get_loc(key)
   3079             except KeyError:
-> 3080                 return self._engine.get_loc(self._maybe_cast_indexer(key))
   3081 
   3082         indexer = self.get_indexer([key], method=method, tolerance=tolerance)

pandas/_libs/index.pyx in pandas._libs.index.DatetimeEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.DatetimeEngine.get_loc()

KeyError: Timestamp('2016-06-01 00:00:00')
...