NCA-ADS - Advanced Data Structures (7% of the exam) - Section 7.1
Handle time-series data.
Handle time-series data by preserving temporal order, engineering lag features and rolling statistics, and avoiding future data leakage in train/test splits. Recognise seasonal decomposition and stationarity as prerequisites for many forecasting approaches.
Practice question for this objective
lock_openFree sampleAdvanced Data Structuresmedium
A data scientist is building a GPU-accelerated model to forecast next week's demand from historical daily sales held in a cuDF DataFrame with a datetime column. To estimate how the model will perform on genuinely future data, how should the train and test sets be split?
AUse the earliest dates for training and the most recent dates for testing, splitting on a cut-off timestamp so the test period strictly follows the training period.check_circle Correct
BShuffle all rows randomly and assign 80 per cent to training and 20 per cent to testing, so both sets cover the full date range evenly.
CApply stratified sampling on the daily_sales value so that the train and test sets share the same distribution of sales magnitudes.
DHold out every seventh day as the test set so that each weekday appears in both training and testing in equal proportion.
Time-series forecasting must use a chronological train/test split so the test period strictly follows the training period and no future data leaks backward. Because each observation depends on time order, a random split lets the model see future-dated rows during training and then evaluate on earlier rows, producing an optimistic estimate that does not reflect true forward prediction; a cut-off-based split preserves the past-predicts-future structure of deployment.
Why A is correct: Splitting on a chronological cut-off keeps all training rows earlier than every test row, which mirrors the real deployment scenario of predicting the future from the past and prevents look-ahead leakage.
Why B is wrong: A uniform random shuffle is the default for non-temporal data, but for forecasting it places future-dated rows in the training set and past-dated rows in the test set, leaking future information and inflating the score.
Why C is wrong: Stratifying on the target balances sales magnitudes across splits, which is useful for imbalanced classification, but it ignores time ordering and still mixes future and past rows across the two sets.
Why D is wrong: Interleaving days by weekday seems to control for day-of-week seasonality, but it scatters test rows throughout the training period, again letting the model train on data that comes after the rows it is evaluated on.
Answers that look right on this material and are not. Each one is a distractor from a different question in the NCA-ADS bank for this domain.
Apply a global shift of 7 rows on the daily_sales column across the entire DataFrame before any grouping step
errorWhy it is wrong: A global shift ignores store boundaries, so the first 7 rows of one store will incorrectly inherit the lagged values from the previous store, contaminating the feature with cross-entity leakage.
Sort the datetime index and then apply a rolling window with a fixed window size equal to the desired interval
errorWhy it is wrong: Rolling windows count a fixed number of rows, not a fixed time span, so on irregular timestamps the window will not correspond to consistent 1-minute periods and the aggregation will be skewed.
Sort the DataFrame by 'event_time' so the string values are in chronological order, which lets time-based operations treat the column as a timeline.
errorWhy it is wrong: Sorting alphabetically on ISO-formatted strings happens to match chronological order, which makes this tempting, but a string column still has no datetime dtype, so resampling and rolling-by-time operations remain unavailable until the type is converted.