# Time Series using Machine Learning models: How to deal with repeated dates and cycles

I'm learning about Time Series forecasting with Machine Learning models like Neural Networks, XGBoost and others. I'm not gonna use ARIMA, SARIMA, ... So, I have the following dataset:

         date     store item  sales
0       2013-01     1    1    13
1       2013-02     1    1    11
2       2013-03     1    1    14
3       2013-04     1    1    13
4       2013-05     1    1    10
...       ...      ...  ...   ...
40      2017-01     1    1    18
41      2017-02     1    1    41
42      2017-03     1    1    23
43      2017-04     1    1    67
44      2017-05     1    1    56
...       ...      ...  ...   ...
912995  2013-01     2    1    63
912996  2013-02     2    1    59
912997  2013-03     2    1    74
912998  2013-04     2    1    62
912999  2013-05     2    1    82


As you can see the dates are repeating like a cycle. This is happening because for each store[1, 10] are records about the sales at that same date interval. [2013, 2017]. The task is predict sales for the next three months. I would like to know what is the best approach to do that considering these repeated dates. I'm considering the following strategies:

1. Train one model for each store. But even if I do that I notice one more thing. This strategy wont work either because if the problem is this dates intervals [2013, 2017] repeating for each store I have the same problem with months and days.

2. Add lag features one for each of the three months, encode this dates with a function very similar to the one bellow. After that I can treat this dataset as a "regular" one and make the traditional train test split and everything else.

.

# not exactly this function. i would change the new features names
def encode_cyclical_atts(dataset, feat_cyclic_names):
cyclic_aux = []
for name in feat_cyclic_names:
column = dataset.loc[:, name]
max_value = column.max()
sin_values = [math.sin((2 * math.pi * x) / max_value) for x in list(column)]
cos_values = [math.cos((2 * math.pi * x) / max_value) for x in list(column)]
cyclic_aux.append(sin_values)
cyclic_aux.append(cos_values)
feat_cyclic_encoded = np.array(cyclic_aux).transpose()

cols_names = ['sin_WindGustDir', 'cos_WindGustDir',
'sin_WindDir9am', 'cos_WindDir9am',
'sin_WindDir3pm', 'cos_WindDir3pm',
'sin_Month', 'cos_Month',
'sin_Day', 'cos_Day']
return pd.DataFrame(data=feat_cyclic_encoded, columns=cols_names)


So what do you think about these approaches?

• Can you edit to ask a more specific question than "What do you think?" This forum works best when users ask specific, focused questions because then answers can address exactly what you want to know about. Open-ended solicitations for thoughts or feedback may be closed as off-topic.
– Sycorax
Commented Apr 29, 2023 at 19:38