2
$\begingroup$

I have time-series data, in which I added a variable "dayofweek" with the day of the week varying from $0$ (Monday) to $6$ (Sunday) (Python's default). I'm using boosting models like GBM and XGBoost to forecast my data. However, should I use a dummy/binary variable for each day of the week or is it the same using one single column for all of them?

     Date     y    dayofweek
01-03-2020   200      6
02-03-2020   250      0
03-03-2020   333      1
04-03-2020   333      2
05-03-2020   200      3
06-03-2020   150      4
07-03-2020   260      5
08-03-2020   300      6

Vs

    Date     y     Monday  Tuesday Wednesday Thursday Friday Saturday Sunday
01-03-2020   200      0        0       0         0      0        0       1
02-03-2020   250      1        0       0         0      0        0       0
03-03-2020   333      0        1       0         0      0        0       0
04-03-2020   333      0        0       1         0      0        0       0
05-03-2020   200      0        0       0         1      0        0       0
06-03-2020   150      0        0       0         0      1        0       0
07-03-2020   260      0        0       0         0      0        1       0
08-03-2020   300      0        0       0         0      0        0       1

I know that these types of models work well with tabular data, but is there any significant difference in results by using dummy/binary vs one single column for days of the week?

$\endgroup$
2
  • 1
    $\begingroup$ Not an answer to your question but you might want to consider whether decision tree based models are really the right approach here, since they can't extrapolate trends into the future. I think all your future predictions will be equal to your in-sample prediction for the latest date in your training set, plus some learned weekly variation. $\endgroup$ – Jonny Lomond Mar 1 at 12:13
  • $\begingroup$ My dataset has much more variables and I'm actually getting good predictions. The dataset I showed here is just an example for the question :) $\endgroup$ – Amateur Mathematician Mar 1 at 14:02
1
$\begingroup$

We encountered the same question when building a recommender system here at Ibotta. If I recall correctly, we didn't find much a difference.

It also may seem the 7th column is redundant. But in a comment, @JonnyLomond pointed out that if not provided, the tree would need to split on all 6 columns (as opposed to one if the 7th is provided).

Which one is better? Try both and compare. If time permits, report your results back here. My instinct is that long format would work better (if any).

$\endgroup$
2
  • $\begingroup$ The 7th column is not redundant in tree models. It's the difference between needing 1 split to isolate Sunday in a node (Sunday > 0.5) and 6 splits (Monday > 0.5 & Tuesday >0.5 & ...) $\endgroup$ – Jonny Lomond Mar 1 at 18:23
  • $\begingroup$ @JonnyLomond That's a good point. I will update my answer. $\endgroup$ – matt Mar 1 at 19:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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