KatInterview

Build and Validate a Multi-Step Sequence Forecaster in PyTorch

Machine LearningModel answer
HardModel answerMachine Learningtime-seriesforecastingpytorch

Last updated

Design an end-to-end forecasting pipeline for a noisy time series: frame the target, avoid leakage, choose a model, write a PyTorch training loop, and evaluate it with time-aware validation.

You are handed a historical time-series dataset (for example, minute-level data with several input features) and asked to produce a model that predicts its future values.

Describe and implement a complete solution:

  1. Problem framing. Which clarifying questions would you ask, and what working assumptions would you state? Consider the target (level versus change), the forecast horizon, how the forecast will be used, data volume, and latency or retraining constraints.
  2. Data preparation. Explain how you build input windows, construct the target, scale features, and split the data so that no future information reaches the model.
  3. Model choice. Pick an architecture, justify it against simpler alternatives, and say which baselines it must beat.
  4. Training code. Write a PyTorch training loop covering the dataset, model, loss, optimizer, regularization, and model selection.
  5. Evaluation. Describe how you would validate the model offline, which metrics you would report, and how you would monitor it after deployment.

Be explicit about your assumptions, the trade-offs behind your choices, and the failure modes you would watch for.

Hints

Hint 1

Before choosing a model, decide what exactly is being predicted: a raw level or a stationary quantity such as a return or difference, and one step ahead or several. This choice drives the loss, the metric and the baseline.

Hint 2

Most forecasting bugs are leakage bugs. Split chronologically, fit scalers on training data only, make sure features at time t use only information available at t, and leave a gap of at least lookback plus horizon between splits.

Hint 3

Start with naive and linear baselines before any neural network. If you do use a sequence model, a direct multi-horizon output head avoids compounding errors, and early stopping plus weight decay guard against overfitting noisy data.