TypeError when trying to make predictions using a fitted ForecasterSarimax object in Skforecast

I’m encountering an error when trying to predict using a fitted forecaster object. I’ve followed this SarimaxForecaster tutorial and I don’t get any error. However my dataset in hourly and when I try to predict, I get the following error –

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>TypeError: Expected index of type <class 'pandas.core.indexes.datetimes.DatetimeIndex'> for `last_window`. Got <class 'pandas.core.indexes.range.RangeIndex'>.
</code>
<code>TypeError: Expected index of type <class 'pandas.core.indexes.datetimes.DatetimeIndex'> for `last_window`. Got <class 'pandas.core.indexes.range.RangeIndex'>. </code>
TypeError: Expected index of type <class 'pandas.core.indexes.datetimes.DatetimeIndex'> for `last_window`. Got <class 'pandas.core.indexes.range.RangeIndex'>.

Seems like something to do with a last_window in the function. See reproducible code and full error log below –

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code># libraries
import pandas as pd
import numpy as np
from skforecast.Sarimax import Sarimax
from skforecast.ForecasterSarimax import ForecasterSarimax
# dataset
start_date = '2023-01-01'
end_date = '2024-01-01'
date_range = pd.date_range(start=start_date, end=end_date, freq='D')
qty = np.random.randint(low=10, high=100, size=len(date_range))
data = pd.DataFrame({'date': date_range, 'qty': qty})
data.set_index('date', inplace=True)
end_train = '2023-11-01'
data_train = df.loc[:end_train]
data_test = df.loc[end_train:]
# changing to series for skforecast
data_train_series = pd.Series(data_train['qty'].values, index=data_train.index, name='qty')
data_test_series = pd.Series(data_test['qty'].values, index=data_test.index, name='qty')
# sarimax forecaster
forecaster = ForecasterSarimax(
regressor=Sarimax(order=(1, 1, 1), seasonal_order=(1, 1, 1, 12))
)
forecaster.fit(y=data_train_series, suppress_warnings=True)
# predict
predictions = forecaster.predict(steps=len(data_test_series))
</code>
<code># libraries import pandas as pd import numpy as np from skforecast.Sarimax import Sarimax from skforecast.ForecasterSarimax import ForecasterSarimax # dataset start_date = '2023-01-01' end_date = '2024-01-01' date_range = pd.date_range(start=start_date, end=end_date, freq='D') qty = np.random.randint(low=10, high=100, size=len(date_range)) data = pd.DataFrame({'date': date_range, 'qty': qty}) data.set_index('date', inplace=True) end_train = '2023-11-01' data_train = df.loc[:end_train] data_test = df.loc[end_train:] # changing to series for skforecast data_train_series = pd.Series(data_train['qty'].values, index=data_train.index, name='qty') data_test_series = pd.Series(data_test['qty'].values, index=data_test.index, name='qty') # sarimax forecaster forecaster = ForecasterSarimax( regressor=Sarimax(order=(1, 1, 1), seasonal_order=(1, 1, 1, 12)) ) forecaster.fit(y=data_train_series, suppress_warnings=True) # predict predictions = forecaster.predict(steps=len(data_test_series)) </code>
# libraries
import pandas as pd
import numpy as np
from skforecast.Sarimax import Sarimax
from skforecast.ForecasterSarimax import ForecasterSarimax

# dataset
start_date = '2023-01-01'
end_date = '2024-01-01'

date_range = pd.date_range(start=start_date, end=end_date, freq='D')
qty = np.random.randint(low=10, high=100, size=len(date_range))
data = pd.DataFrame({'date': date_range, 'qty': qty})
data.set_index('date', inplace=True)

end_train = '2023-11-01'

data_train = df.loc[:end_train]
data_test  = df.loc[end_train:]


# changing to series for skforecast
data_train_series = pd.Series(data_train['qty'].values, index=data_train.index, name='qty')
data_test_series  = pd.Series(data_test['qty'].values, index=data_test.index, name='qty')

# sarimax forecaster
forecaster = ForecasterSarimax(
                 regressor=Sarimax(order=(1, 1, 1), seasonal_order=(1, 1, 1, 12))
            )

forecaster.fit(y=data_train_series, suppress_warnings=True)

# predict
predictions = forecaster.predict(steps=len(data_test_series))

Full Error Log –

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>TypeError Traceback (most recent call last)
File ~/Desktop/School/2024_projects/time_series_feature_engineering/practice/01_bakery_skforecast_quickstart.py:1
----> 1 predictions = forecaster.predict(steps=len(data_test_series))
File ~/Desktop/School/2024_projects/time_series_feature_engineering/.venv/lib/python3.9/site-packages/skforecast/ForecasterSarimax/ForecasterSarimax.py:363, in ForecasterSarimax.predict(self, steps, last_window, last_window_exog, exog)
359 # Needs to be a new variable to avoid arima_res_.append when using
360 # self.last_window. It already has it stored.
361 last_window_check = last_window if last_window is not None else self.last_window
--> 363 check_predict_input(
364 forecaster_name = type(self).__name__,
365 steps = steps,
366 fitted = self.fitted,
367 included_exog = self.included_exog,
368 index_type = self.index_type,
369 index_freq = self.index_freq,
370 window_size = self.window_size,
371 last_window = last_window_check,
372 last_window_exog = last_window_exog,
373 exog = exog,
374 exog_type = self.exog_type,
375 exog_col_names = self.exog_col_names,
376 interval = None,
377 alpha = None,
378 max_steps = None,
379 levels = None,
380 series_col_names = None
381 )
383 # If not last_window is provided, last_window needs to be None
384 if last_window is not None:
File ~/Desktop/School/2024_projects/time_series_feature_engineering/.venv/lib/python3.9/site-packages/skforecast/utils/utils.py:643, in check_predict_input(forecaster_name, steps, fitted, included_exog, index_type, index_freq, window_size, last_window, last_window_exog, exog, exog_type, exog_col_names, interval, alpha, max_steps, levels, series_col_names)
638 _, last_window_index = preprocess_last_window(
639 last_window = last_window.iloc[:0],
640 return_values = False
641 )
642 if not isinstance(last_window_index, index_type):
--> 643 raise TypeError(
644 (f"Expected index of type {index_type} for `last_window`. "
645 f"Got {type(last_window_index)}.")
646 )
647 if isinstance(last_window_index, pd.DatetimeIndex):
648 if not last_window_index.freqstr == index_freq:
TypeError: Expected index of type <class 'pandas.core.indexes.datetimes.DatetimeIndex'> for `last_window`. Got <class 'pandas.core.indexes.range.RangeIndex'>.
</code>
<code>TypeError Traceback (most recent call last) File ~/Desktop/School/2024_projects/time_series_feature_engineering/practice/01_bakery_skforecast_quickstart.py:1 ----> 1 predictions = forecaster.predict(steps=len(data_test_series)) File ~/Desktop/School/2024_projects/time_series_feature_engineering/.venv/lib/python3.9/site-packages/skforecast/ForecasterSarimax/ForecasterSarimax.py:363, in ForecasterSarimax.predict(self, steps, last_window, last_window_exog, exog) 359 # Needs to be a new variable to avoid arima_res_.append when using 360 # self.last_window. It already has it stored. 361 last_window_check = last_window if last_window is not None else self.last_window --> 363 check_predict_input( 364 forecaster_name = type(self).__name__, 365 steps = steps, 366 fitted = self.fitted, 367 included_exog = self.included_exog, 368 index_type = self.index_type, 369 index_freq = self.index_freq, 370 window_size = self.window_size, 371 last_window = last_window_check, 372 last_window_exog = last_window_exog, 373 exog = exog, 374 exog_type = self.exog_type, 375 exog_col_names = self.exog_col_names, 376 interval = None, 377 alpha = None, 378 max_steps = None, 379 levels = None, 380 series_col_names = None 381 ) 383 # If not last_window is provided, last_window needs to be None 384 if last_window is not None: File ~/Desktop/School/2024_projects/time_series_feature_engineering/.venv/lib/python3.9/site-packages/skforecast/utils/utils.py:643, in check_predict_input(forecaster_name, steps, fitted, included_exog, index_type, index_freq, window_size, last_window, last_window_exog, exog, exog_type, exog_col_names, interval, alpha, max_steps, levels, series_col_names) 638 _, last_window_index = preprocess_last_window( 639 last_window = last_window.iloc[:0], 640 return_values = False 641 ) 642 if not isinstance(last_window_index, index_type): --> 643 raise TypeError( 644 (f"Expected index of type {index_type} for `last_window`. " 645 f"Got {type(last_window_index)}.") 646 ) 647 if isinstance(last_window_index, pd.DatetimeIndex): 648 if not last_window_index.freqstr == index_freq: TypeError: Expected index of type <class 'pandas.core.indexes.datetimes.DatetimeIndex'> for `last_window`. Got <class 'pandas.core.indexes.range.RangeIndex'>. </code>
TypeError                                 Traceback (most recent call last)
File ~/Desktop/School/2024_projects/time_series_feature_engineering/practice/01_bakery_skforecast_quickstart.py:1
----> 1 predictions = forecaster.predict(steps=len(data_test_series))

File ~/Desktop/School/2024_projects/time_series_feature_engineering/.venv/lib/python3.9/site-packages/skforecast/ForecasterSarimax/ForecasterSarimax.py:363, in ForecasterSarimax.predict(self, steps, last_window, last_window_exog, exog)
    359 # Needs to be a new variable to avoid arima_res_.append when using 
    360 # self.last_window. It already has it stored.
    361 last_window_check = last_window if last_window is not None else self.last_window
--> 363 check_predict_input(
    364     forecaster_name  = type(self).__name__,
    365     steps            = steps,
    366     fitted           = self.fitted,
    367     included_exog    = self.included_exog,
    368     index_type       = self.index_type,
    369     index_freq       = self.index_freq,
    370     window_size      = self.window_size,
    371     last_window      = last_window_check,
    372     last_window_exog = last_window_exog,
    373     exog             = exog,
    374     exog_type        = self.exog_type,
    375     exog_col_names   = self.exog_col_names,
    376     interval         = None,
    377     alpha            = None,
    378     max_steps        = None,
    379     levels           = None,
    380     series_col_names = None
    381 )
    383 # If not last_window is provided, last_window needs to be None
    384 if last_window is not None:

File ~/Desktop/School/2024_projects/time_series_feature_engineering/.venv/lib/python3.9/site-packages/skforecast/utils/utils.py:643, in check_predict_input(forecaster_name, steps, fitted, included_exog, index_type, index_freq, window_size, last_window, last_window_exog, exog, exog_type, exog_col_names, interval, alpha, max_steps, levels, series_col_names)
    638 _, last_window_index = preprocess_last_window(
    639                            last_window   = last_window.iloc[:0],
    640                            return_values = False
    641                        ) 
    642 if not isinstance(last_window_index, index_type):
--> 643     raise TypeError(
    644         (f"Expected index of type {index_type} for `last_window`. "
    645          f"Got {type(last_window_index)}.")
    646     )
    647 if isinstance(last_window_index, pd.DatetimeIndex):
    648     if not last_window_index.freqstr == index_freq:

TypeError: Expected index of type <class 'pandas.core.indexes.datetimes.DatetimeIndex'> for `last_window`. Got <class 'pandas.core.indexes.range.RangeIndex'>.


Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật