I am trying to execute the the code below but i keep getting an assertion error:
from sktime.forecasting.base import ForecastingHorizon
fh = ForecastingHorizon(
pd.PeriodIndex(pd.date_range("2023-01-01", periods=6, freq="M")), is_relative=False
)
cutoff = pd.Period("2022-12-01", freq="M")
fh.to_relative(cutoff)
from sktime.forecasting.naive import NaiveForecaster
forecaster = NaiveForecaster(strategy="last", sp=12)
forecaster.fit(water_data)
water_data.info()
y_pred = forecaster.predict(fh)
The error stack is looks like this
AssertionError Traceback (most recent call last)
Cell In[111], line 1
----> 1 y_pred = forecaster.predict(fh)
File D:\ML Projects\Bityarn-UtilitiesAnalysis\venv\lib\site-packages\sktime\forecasting\base\_base.py:404, in BaseForecaster.predict(self, fh, X)
402 # we call the ordinary _predict if no looping/vectorization needed
403 if not self._is_vectorized:
--> 404 y_pred = self._predict(fh=fh, X=X_inner)
405 else:
406 # otherwise we call the vectorized version of predict
407 y_pred = self._vectorize("predict", X=X_inner, fh=fh)
File D:\ML Projects\Bityarn-UtilitiesAnalysis\venv\lib\site-packages\sktime\forecasting\naive.py:336, in NaiveForecaster._predict(self, fh, X)
326 def _predict(self, fh=None, X=None):
327 """Forecast time series at future horizon.
328
329 Parameters
(...)
334 Exogenous time series
335 """
--> 336 y_pred = super(NaiveForecaster, self)._predict(fh=fh, X=X)
338 # test_predict_time_index_in_sample_full[ForecastingPipeline-0-int-int-True]
339 # causes a pd.DataFrame to appear as y_pred, which upsets the next lines
340 # reasons are unclear, this is coming from the _BaseWindowForecaster
341 # todo: investigate this
342 if isinstance(y_pred, pd.DataFrame):
File D:\ML Projects\Bityarn-UtilitiesAnalysis\venv\lib\site-packages\sktime\forecasting\base\_sktime.py:30, in _BaseWindowForecaster._predict(self, fh, X)
27 kwargs = {"X": X}
29 # all values are out-of-sample
---> 30 if fh.is_all_out_of_sample(self.cutoff):
31 return self._predict_fixed_cutoff(
32 fh.to_out_of_sample(self.cutoff), **kwargs
33 )
35 # all values are in-sample
File D:\ML Projects\Bityarn-UtilitiesAnalysis\venv\lib\site-packages\sktime\forecasting\base\_fh.py:612, in ForecastingHorizon.is_all_out_of_sample(self, cutoff)
597 def is_all_out_of_sample(self, cutoff=None) -> bool:
598 """Whether the forecasting horizon is purely out-of-sample for given cutoff.
599
600 Parameters
(...)
610 cutoff.
611 """
--> 612 return sum(self._is_out_of_sample(cutoff)) == len(self)
File D:\ML Projects\Bityarn-UtilitiesAnalysis\venv\lib\site-packages\sktime\forecasting\base\_fh.py:595, in ForecastingHorizon._is_out_of_sample(self, cutoff)
593 def _is_out_of_sample(self, cutoff=None) -> np.ndarray:
594 """Get index location of out-of-sample values."""
--> 595 return np.logical_not(self._is_in_sample(cutoff))
File D:\ML Projects\Bityarn-UtilitiesAnalysis\venv\lib\site-packages\sktime\forecasting\base\_fh.py:574, in ForecastingHorizon._is_in_sample(self, cutoff)
572 def _is_in_sample(self, cutoff=None) -> np.ndarray:
573 """Get index location of in-sample values."""
--> 574 relative = self.to_relative(cutoff).to_pandas()
575 null = 0 if is_integer_index(relative) else pd.Timedelta(0)
576 return relative <= null
File D:\ML Projects\Bityarn-UtilitiesAnalysis\venv\lib\site-packages\sktime\forecasting\base\_fh.py:461, in ForecastingHorizon.to_relative(self, cutoff)
446 """Return forecasting horizon values relative to a cutoff.
447
448 Parameters
(...)
458 Relative representation of forecasting horizon.
459 """
460 cutoff = self._coerce_cutoff_to_index_element(cutoff)
--> 461 return _to_relative(fh=self, cutoff=cutoff)
File D:\ML Projects\Bityarn-UtilitiesAnalysis\venv\lib\site-packages\sktime\forecasting\base\_fh.py:682, in _to_relative(fh, cutoff)
680 else:
681 absolute = fh.to_pandas()
--> 682 _check_cutoff(cutoff, absolute)
684 if isinstance(absolute, pd.DatetimeIndex):
685 # coerce to pd.Period for reliable arithmetics and computations of
686 # time deltas
687 absolute = _coerce_to_period(absolute, freq=fh.freq)
File D:\ML Projects\Bityarn-UtilitiesAnalysis\venv\lib\site-packages\sktime\forecasting\base\_fh.py:776, in _check_cutoff(cutoff, index)
773 raise ValueError("`cutoff` must be given, but found none.")
775 if isinstance(index, pd.PeriodIndex):
--> 776 assert isinstance(cutoff, pd.Period)
777 assert index.freqstr == cutoff.freqstr
779 if isinstance(index, pd.DatetimeIndex):
AssertionError:
The water_data has 49 data points with a datetime index and a floating point value. What could be the issue. I am following the tutorial on the official website. Could the problem be the data am passing to the model.