What is the reason of setting a gap between the end of the train set and the beginning of the test set? When splitting train/test data sets there is an option to set a gap between them. For example, given a series of 100 days, we can split as follows: train = 80, gap = 1, test = 19. In the materials I'm learning, however, there isn't a clear explanation why to do or not to do so, and how to determine the gap length. I can guess that leaving a gap may be helpful in addressing overfitting, but would appreciate if you can point me to a reference.
EDIT: For further clarification, I'm working with time series data cross-validation. For example, this gap setting can be found in sklearn.model_selection.TimeSeriesSplit. According to the user's guide:
sklearn.model_selection.TimeSeriesSplit(n_splits=5, *, max_train_size=None, test_size=None, gap=0)
in which gap is the number of samples to exclude from the end of each train set before the test set.

There are two possible reasons that I've heard:

*

*data leakage from forward-looking variables.  If you create your target or features by looking ahead (e.g. if the target is whether to buy a stock, you may look at the stock price a day or two ahead), then those variables at the end of the training set have incorporated some of the test set's information.  (In a lot of cases, I suspect you could avoid this just be reframing the prediction: predict the stock price instead, e.g.)


*that's just what you're interested in.  If you care about long-term prediction quality, your test set should reflect that by being long-term predictions.  Most models will perform best soon after training and then fall off (especially depending on how autocorrelated the predictions are, which depends on how you set up the problem), so skipping the honeymoon period might lead to better comparisons between models.  (And, I'm making this one up, but if it takes you some number of days to release a model to production, your trained model won't actually get to predict on the gap anyway.)
From the perspective of sklearn, here's the PR that added gap (that alludes to (1) above), and a motivating issue comment (that mentions (2) above).
