0

I have fit SKTime's Croston class on my training time series data and I needed to get its fitted values. By following the discussion here, I was able to produce the predictions for the dates of my sample, but they are of the same value only in contrast to the output produced by the code in this towardsdatascience article which was said to be referenced by the class in the SKTime documentation. Does anyone happen to know if this is a bug or is my code wrong? I have below the code for reproducible output.

from pandas import Timestamp
import pandas as pd
from sktime.forecasting.croston import Croston
from sktime.forecasting.base import ForecastingHorizon

train_data = pd.DataFrame.from_dict({'No. of Projects': {Timestamp('2016-07-31 00:00:00', freq='M'): 9,
  Timestamp('2016-08-31 00:00:00', freq='M'): 4,
  Timestamp('2016-09-30 00:00:00', freq='M'): 6,
  Timestamp('2016-10-31 00:00:00', freq='M'): 6,
  Timestamp('2016-11-30 00:00:00', freq='M'): 13,
  Timestamp('2016-12-31 00:00:00', freq='M'): 10,
  Timestamp('2017-01-31 00:00:00', freq='M'): 22,
  Timestamp('2017-02-28 00:00:00', freq='M'): 26,
  Timestamp('2017-03-31 00:00:00', freq='M'): 13,
  Timestamp('2017-04-30 00:00:00', freq='M'): 21,
  Timestamp('2017-05-31 00:00:00', freq='M'): 29,
  Timestamp('2017-06-30 00:00:00', freq='M'): 13,
  Timestamp('2017-07-31 00:00:00', freq='M'): 11,
  Timestamp('2017-08-31 00:00:00', freq='M'): 26,
  Timestamp('2017-09-30 00:00:00', freq='M'): 19,
  Timestamp('2017-10-31 00:00:00', freq='M'): 23,
  Timestamp('2017-11-30 00:00:00', freq='M'): 15,
  Timestamp('2017-12-31 00:00:00', freq='M'): 13,
  Timestamp('2018-01-31 00:00:00', freq='M'): 17,
  Timestamp('2018-02-28 00:00:00', freq='M'): 16,
  Timestamp('2018-03-31 00:00:00', freq='M'): 26,
  Timestamp('2018-04-30 00:00:00', freq='M'): 10,
  Timestamp('2018-05-31 00:00:00', freq='M'): 13,
  Timestamp('2018-06-30 00:00:00', freq='M'): 8,
  Timestamp('2018-07-31 00:00:00', freq='M'): 24,
  Timestamp('2018-08-31 00:00:00', freq='M'): 7,
  Timestamp('2018-09-30 00:00:00', freq='M'): 17,
  Timestamp('2018-10-31 00:00:00', freq='M'): 12,
  Timestamp('2018-11-30 00:00:00', freq='M'): 20,
  Timestamp('2018-12-31 00:00:00', freq='M'): 9,
  Timestamp('2019-01-31 00:00:00', freq='M'): 22,
  Timestamp('2019-02-28 00:00:00', freq='M'): 17,
  Timestamp('2019-03-31 00:00:00', freq='M'): 25,
  Timestamp('2019-04-30 00:00:00', freq='M'): 21,
  Timestamp('2019-05-31 00:00:00', freq='M'): 19,
  Timestamp('2019-06-30 00:00:00', freq='M'): 11,
  Timestamp('2019-07-31 00:00:00', freq='M'): 4,
  Timestamp('2019-08-31 00:00:00', freq='M'): 4,
  Timestamp('2019-09-30 00:00:00', freq='M'): 4,
  Timestamp('2019-10-31 00:00:00', freq='M'): 19,
  Timestamp('2019-11-30 00:00:00', freq='M'): 21,
  Timestamp('2019-12-31 00:00:00', freq='M'): 27,
  Timestamp('2020-01-31 00:00:00', freq='M'): 27,
  Timestamp('2020-02-29 00:00:00', freq='M'): 23,
  Timestamp('2020-03-31 00:00:00', freq='M'): 2,
  Timestamp('2020-04-30 00:00:00', freq='M'): 4,
  Timestamp('2020-05-31 00:00:00', freq='M'): 4,
  Timestamp('2020-06-30 00:00:00', freq='M'): 4}})

model = Croston(smoothing=0.1)
fh_of_fitted = ForecastingHorizon(train_data.index, is_relative=False)  # in-sample forecasting horizon
in_sample_pred = model.fit(train_data).predict( fh=fh_of_fitted)
print(in_sample_pred)
Nagusameta
  • 109
  • 8

0 Answers0