I am trying to predict future stock market values using a gradient boosted tree model. As far as I know, gradient boosted trees use the data in one row, and only that row, to predict the target variable for that row.

Therefore, I am thinking that setting up the training dataset like this would not cause data leakage?

enter image description here

Would this count as roll-forward partitioning in some sense, because for each row, the last year's worth of historical values are provided?

  • $\begingroup$ This isn't data leakage but also a really inefficient way to model a time series. You are basically "hard codding" earlier values and try to use them as a predictor in a "static model". When predicting time series you have to go about it in a different way. I suggest looking at ARIMA / Prophet / etc. to get going in that direction. $\endgroup$ – Fnguyen Jul 14 at 13:02
  • 1
    $\begingroup$ No, not leakage. I've used this method and had great success with it. It certainly relies on you transforming the target so that its stationary, though. A tree based model won't predict a target value outside of the ranges that it obeserved, so remember that. Another thing to consider is: are you only predicting one period ahead (or the 3 days time value is only 1 point in reference to the date columns) .. if not, you can still extend this by adding a "forecast distance" variable which is the time between the date and the start of your target. $\endgroup$ – Josh Jul 14 at 20:32
  • 1
    $\begingroup$ I tend to avoid stock market problems in general :). I have played with predicting something like stock dispersion which is generally easier because it tends to be high or low over longer periods. $\endgroup$ – Josh Jul 14 at 21:26
  • 1
    $\begingroup$ Definitely transform the target if it was stock prices. Log might work since stocks never really hit 0. Here's a nice link that outlines how to test for stationary: towardsdatascience.com/… Just ignore the ARIMA part if you want to do it this way. Oh one other thing - this technique seems to be more powerful for me when you have a lot of covariates for each day, including categorical. When its just the lagged target then its not as exciting to do.. but have fun storming the castle! $\endgroup$ – Josh Jul 14 at 21:32
  • 1
    $\begingroup$ Make sure you parse out day of week, month, holiday/weekends, and other fun date variables from that date! If you have a calendar of holidays you can add variables like "days until holiday X" etc! $\endgroup$ – Josh Jul 14 at 21:33

Your Answer

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

Browse other questions tagged or ask your own question.