0
$\begingroup$

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?

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$
    – Sycorax
    Commented Apr 29, 2023 at 19:38

1 Answer 1

1
$\begingroup$

A few things I can think of here. If you're just trying to predict sales for a specific store, you can sum up each store's item sales and predict total sales. That's one way to do it.

If you're trying to predict specific item sales, then you could group monthly sales by store and item on a monthly basis.

In either case, you can add time series features using a package like tsfresh. This gives you a bunch of time series features for each store or store/item combo. Then you use dates for three months out or total of next three month sales as your target variable and train.

This is also a problem in time series forecasting of a top down vs bottom up approach. Predict in aggregate then predict for each item or predict for each item then predict in aggregate. Here a few links to read up on those two strategies. Hope this helps.

https://towardsdatascience.com/introduction-to-hierarchical-time-series-forecasting-part-i-88a116f2e2

https://quickbooks.intuit.com/r/growing-a-business/top-down-vs-bottom-up-which-financial-forecasting-model-works-for-you/

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.