darts icon indicating copy to clipboard operation
darts copied to clipboard

[QUESTION] Croston and add_encoders

Open sebros-sandvik opened this issue 1 year ago • 5 comments

Hi,

I cant get add_encoders functionality (for Croston) to work, see below

image

temporal_cv_lf basically just calls

m = Croston(**params)

m.historical_forecasts(series=series, forecast_horizon=forecast_horizon, last_points_only=False, overlap_end=False, stride=1, retrain=True))

Any help would be appreciated

sebros-sandvik avatar Jan 27 '24 11:01 sebros-sandvik

Hi @sebros-sandvik, Darts' Croston model doesn't support covariates, and can therefore not use the encoders. You can find which models support covariates in the model support table here.

dennisbader avatar Jan 29 '24 07:01 dennisbader

Hi,

Ok just fyi if this needs changing : image

sebros-sandvik avatar Jan 29 '24 07:01 sebros-sandvik

Sorry, my bad. Actually the model support table is not correct. We'll fix that ASAP. Croston method indeed supports future covariates.

Can you provide a minimal reproducible example and the error message that you receive?

dennisbader avatar Jan 29 '24 14:01 dennisbader

Hi @dennisbader ,

of course sir:

import pandas as pd
from darts.models import Croston
from darts import TimeSeries, concatenate
import numpy as np

dates = pd.date_range(start='2019-02-01', end='2023-03-01', freq='MS')
month = dates.month
np.random.seed(1)
noise = np.random.normal(0, 1, len(dates))
sales = month + noise
data = pd.DataFrame({'date': dates, 'sales': sales})
series = TimeSeries.from_dataframe(data, 'date', 'sales')

params1 = {'version': 'tsb', 'alpha_d': 0.7056278684620902, 'alpha_p': 0.12437058458227879}
params2 = {'version': 'tsb', 'alpha_d': 0.7056278684620902, 'alpha_p': 0.12437058458227879,
           'add_encoders': {'cyclic': {'future': ['month']}}}

m1 = Croston(**params1)
m2 = Croston(**params2)

pred1 = concatenate(m1.historical_forecasts(series=series,
                               forecast_horizon=1,
                               last_points_only=False,
                               overlap_end=False,
                               stride=1, 
                               retrain=True))

pred2 = concatenate(m2.historical_forecasts(series=series,
                               forecast_horizon=1,
                               last_points_only=False,
                               overlap_end=False,
                               stride=1, 
                               retrain=True))

print(pred1 == pred2)

sebros-sandvik avatar Jan 30 '24 09:01 sebros-sandvik

Hi @sebros-sandvik,

After inspecting the implementation of Croston, it seems like the covariates (X in their API) is only used when using conformal prediction (not yet supported by Darts).

We will revert the changes to the table and update the constructor of this model to remove the add_encoders argument as it actually does not support future covariates.

Sorry for the confusion and the delay.

madtoinou avatar Aug 16 '24 09:08 madtoinou