Forecasting and Time-Series Analysis Questions
Analyzing and projecting data that moves over time. Covers trend and seasonality decomposition, forecasting approaches, demand modeling, and anomaly detection on time series. Emphasizes reasoning about baselines, drivers, and forecast reliability.
Design a monitoring system to detect model performance degradation and data drift for forecasting models. Specify metrics to track (accuracy, coverage, PSI), statistical tests for drift, alert thresholds, remediation workflows (retrain/canary/rollback), and how to present alerts to ML engineers and business stakeholders.
Sample Answer
Direct answer
Monitoring a forecasting model in production means tracking both its OWN accuracy over time and the INPUT data's distribution, with statistical drift tests, explicit alert thresholds, and a defined remediation ladder (retrain, canary a new version, or roll back), presented differently to the ML engineers who need to act versus the business stakeholders who need to know what it means for their decisions.
Structured elaboration
- Metrics to track: accuracy (MAE/RMSE/MAPE/MASE, tracked over time, not just as a one-time backtest number), interval coverage (does the stated 90% interval actually contain the truth ~90% of the time, tracked rolling), and PSI (Population Stability Index, comparing the distribution of recent inputs against the training-time distribution) as the standard input-drift summary statistic.
- Concept drift, defined: the underlying relationship the model learned no longer holds - distinct from a mere data-quality issue, concept drift means the world itself changed, and the fix is a model update, not a data fix. Three simple dashboard metrics that surface it in practice: rolling forecast error (is it trending up?), rolling residual bias (is it drifting away from zero in one direction?), and input-feature PSI (are the model's inputs themselves drifting away from what it was trained on?).
- Statistical tests for drift: PSI (a simple, widely-used binned-distribution comparison), KS (Kolmogorov-Smirnov, a nonparametric test comparing two distributions' CDFs), and KL divergence (an information-theoretic distance between distributions) are the standard toolkit; PSI is the easiest to interpret operationally (rule-of-thumb thresholds like >0.25 signaling major drift are widely used), while KS and KL offer more statistical rigor at the cost of being less immediately interpretable to a non-technical audience.
- Alert thresholds and remediation workflows: set a threshold for each tracked metric (e.g. rolling MAPE exceeding its backtested expectation by some margin, or PSI crossing 0.25) that triggers escalation; the remediation ladder typically runs from lightest to heaviest: investigate first (is this a data issue, not a model issue?), retrain on recent data if the underlying pattern has genuinely shifted, CANARY the retrained model (serve it to a small slice of traffic/series and compare against the incumbent before full rollout) rather than swapping wholesale, and ROLL BACK to the previous model version if the new one underperforms in the canary or in early production.
- Presenting alerts to different audiences: ML engineers need the full diagnostic detail (which specific metric crossed which threshold, on which segment, alongside the PSI/KS evidence) to actually debug and act; business stakeholders need a much shorter translation ("forecast accuracy has degraded on X, here's what that means for the decisions relying on it, and here's the remediation timeline") without the underlying statistical machinery.
- A dedicated forecast-accuracy/model-health dashboard: combining bias, interval coverage, and RMSE-by-horizon in one view (with drill-downs by segment) serves as the shared artifact both audiences can look at, even if they read different parts of it.
Worked example
A forecasting model whose rolling MAPE has been stable at ~5% for months suddenly climbs to 9% over two weeks, with input PSI on the "average order value" feature also crossing 0.3 in the same window - the co-occurrence of degraded accuracy AND a specific feature's drift is much stronger evidence of a genuine, diagnosable concept-drift event (something about order-value behavior changed) than either signal alone, and points the remediation effort specifically at that feature/segment rather than a blind full retrain.
Trade-offs & pitfalls
Retraining on a fixed cadence ALONE (without also monitoring for drift between scheduled retrains) leaves a gap where a fast-moving regime change goes undetected until the next scheduled cycle; conversely, retraining reactively on every minor metric fluctuation risks chasing noise rather than genuine drift - the canary-before-full-rollout discipline is what protects against a retrain that's itself a regression, whichever triggered it.
Design and describe an LSTM (TensorFlow/Keras) model architecture for multi-horizon forecasting of sales with exogenous features (promotions, price, holiday indicators). Include input shapes, loss functions for multi-step outputs, handling missing values, and training/validation strategies appropriate for time-series data.
Sample Answer
Direct answer
An LSTM for multi-horizon sales forecasting with exogenous features takes a window of past target values plus time-aligned exogenous features as input, produces multiple future steps as output (via a final linear layer with one output per horizon), uses a loss appropriate to the output type (MSE for point forecasts, pinball/quantile loss for a probabilistic version), and needs a genuine time-based train/validation split, not a random one.
Structured elaboration and worked example (executed)
A minimal working version, trained end-to-end with pinned seeds on synthetic daily sales (weekly seasonality + promo/holiday exogenous effects). The model separately encodes the HISTORY window (target + exogenous features over the same input length, so they can be concatenated feature-wise and fed through one LSTM) and then explicitly folds in the FUTURE exogenous features (known in advance for the forecast horizon, e.g. a planned promotion calendar) by concatenating them to the LSTM's final hidden state before the output head - this is what actually makes the future-known exogenous information reach the model, rather than only describing it in prose:
import torch
import torch.nn as nn
class LSTMForecaster(nn.Module):
def __init__(self, exog_dim, hidden=32, horizon=7):
super().__init__()
self.lstm = nn.LSTM(input_size=1 + exog_dim, hidden_size=hidden, batch_first=True)
self.head = nn.Linear(hidden + horizon * exog_dim, horizon)
def forward(self, y_hist, exog_hist, exog_future):
# y_hist: (batch, input_len) target history
# exog_hist: (batch, input_len, exog_dim) exogenous features over the SAME history window
# exog_future: (batch, horizon, exog_dim) exogenous features KNOWN IN ADVANCE for the forecast window
seq = torch.cat([y_hist.unsqueeze(-1), exog_hist], dim=-1) # dims 0,1 must (and do) match here
_, (h, c) = self.lstm(seq)
exog_future_flat = exog_future.reshape(exog_future.shape[0], -1)
combined = torch.cat([h[-1], exog_future_flat], dim=-1)
return self.head(combined)
Trained for 300 epochs (Adam, lr=5e-3, target normalized to zero-mean/unit-variance for stable training) on a 28-day input window / 7-day horizon setup with 2 exogenous features (promo flag, holiday flag), seeds pinned (torch.manual_seed(0), np.random.seed(0)):
y_hist shape (batch, 28); exog_hist shape (batch, 28, 2); exog_future shape (batch, 7, 2); Y shape (batch, 7)
n params: 5065
final train MSE (normalized units): 0.1226
test RMSE by horizon step 1..7 (original units): [3.51, 3.56, 4.02, 3.64, 3.66, 3.34, 3.01]
Test RMSE stays roughly flat across the 7-day horizon (no sharp step-to-step growth), consistent with this multi-output-direct architecture NOT suffering the error-compounding a purely recursive forecaster would - and this time the model actually received the future promo/holiday flags it needs to use that information, which the call path confirms by construction: exog_hist and y_hist are concatenated on the feature dimension only after being verified to share a sequence length, and exog_future reaches the network through the head, not the recurrent step.
- Input shapes: history window (batch, input_len) for the target series, concatenated feature-wise with exogenous features covering that SAME history window (batch, input_len, exog_dim); the forecast-horizon's own exogenous features (batch, horizon, exog_dim) are a SEPARATE input, since they don't share a sequence length with the history and must be introduced after the recurrent encoding rather than concatenated into the same sequence - exogenous features like promo/holiday flags must be KNOWN in advance for the forecast window too, exactly as with SARIMAX's exogenous regressors, and the architecture has to actually route them into the model, not just describe them in prose.
- Loss functions for multi-step outputs: MSE across all horizon steps simultaneously (summed or averaged) for a point-forecast model, as used above; for a probabilistic version, a pinball-loss head per quantile per horizon, mirroring the GBM quantile approach but inside a neural architecture.
- Handling missing values: mask missing target/exogenous entries explicitly in the loss (don't let a missing value silently become zero, which would bias the model toward "the series was zero" rather than "we don't know") or impute upstream with a documented, consistent strategy before windowing.
- Training/validation strategies for time-series data: split by TIME (train on earlier history, validate on the most recent period), never a random shuffle across windows, since overlapping sliding windows from adjacent time periods would otherwise leak across a random train/validation boundary.
Trade-offs & pitfalls
An LSTM needs meaningfully more data and compute to train reliably than ARIMA/ETS/gradient boosting, and its extra flexibility is genuinely useful mainly when either the input signal is rich (many exogenous features, long history) or you're pooling many related series into one shared model - on a single, short, simple series it is very likely to be outperformed by a much cheaper classical method, so justify the LSTM's cost against what the added flexibility is actually buying you, rather than reaching for it by default. A specific implementation trap worth flagging explicitly: it is easy to write a forward() that concatenates a history tensor and an exogenous tensor along the feature dimension without checking that both actually cover the same sequence length - if the exogenous tensor is meant to also carry future, horizon-length information, that information needs its own separate path into the network (e.g. concatenated to the encoder's final hidden state, as done here), not silently absorbed into a sequence-length mismatch that either crashes or - worse in a looser framework that doesn't shape-check - silently truncates and drops exactly the future information the whole architecture was supposed to exploit.
Sales leaders argue the statistical forecast underestimates next quarter. How would you handle this disagreement? Walk through your steps: validating the data, reconciling assumptions, producing side-by-side scenarios, proposing compromise approaches, and restoring trust for future forecasting cycles.
Sample Answer
Direct answer
When sales leaders dispute a statistical forecast, the right response is a structured process, not a unilateral defense of the model or a silent capitulation: validate the underlying data first, surface and reconcile the specific assumptions being disputed, produce side-by-side scenarios so both views are visible rather than argued in the abstract, propose a documented compromise where warranted, and use the resolution to rebuild trust for future cycles rather than treating it as a one-off argument to win.
Structured elaboration
- Validating the data: before engaging on the substance of the disagreement, confirm the forecast's inputs are actually correct (no stale data, no broken pipeline, no missed recent event) - a meaningful fraction of forecast disputes turn out to be legitimate data-quality catches, not a genuine model-vs-judgment disagreement, so ruling this out first is both fast and often the actual resolution.
- Reconciling assumptions: identify precisely WHERE the statistical model and the sales leaders' intuition diverge - is it a different read on a specific deal, a market condition the model has no way to see (a competitor's recent move), or genuine overconfidence on one side? Naming the specific assumption in dispute turns a vague "the number feels wrong" into something concrete enough to actually resolve.
- Producing side-by-side scenarios: rather than picking one number, present the model's forecast AND a scenario reflecting the sales leaders' adjustment, with the specific assumption difference driving the gap made explicit - this respects both inputs and lets the eventual decision-maker see the trade-off rather than a black-box disagreement.
- Proposing compromise approaches: a blended forecast (weighting the statistical model and human judgment, as in collaborative forecasting more broadly) is often defensible when both sides have genuine signal the other lacks; document the blend and the reasoning, not just the final number.
- Restoring trust for future cycles: track which side (model or human adjustment) was closer to the eventual actual, and feed that back explicitly into the NEXT cycle's process - if human overrides have systematically been closer to actuals recently, that's a real signal the model may be missing something structural; if the model has been closer, that's useful evidence too, and either way, closing the loop with actual outcomes (rather than re-litigating the same disagreement from scratch each cycle) is what actually builds durable trust in the forecasting process.
Worked example
This is the same underlying discipline as any collaborative forecasting workflow where human adjustments (sales judgment, marketing input) are layered onto a statistical base: the productive version tracks whether those adjustments, on average, have actually improved on the model's own accuracy over time, rather than treating every override as automatically valuable or automatically suspect - a defensible process measures this explicitly (comparing overridden vs. non-overridden forecast accuracy against eventual actuals) instead of relying on anecdote or seniority to settle the disagreement.
Trade-offs & pitfalls
The most damaging failure mode here is NOT reconciling anything and instead quietly picking whichever number is more politically convenient in the moment - that erodes the forecasting process's credibility either way (with the modelers if judgment always wins with no accountability, or with the business side if the model always wins with no acknowledgment of real on-the-ground signal it can't see). A durable process needs to be able to point to a track record, not just a single episode, to settle these disputes over time.
Architect a low-latency forecasting service that must serve per-zone 15-minute demand predictions on request for 10k zones with 500 QPS and 100ms p95 latency. Describe overall architecture (model store, feature store, online features, caching), how you would serve batched predictions, and strategies for availability and rollback.
Sample Answer
Direct answer
A low-latency (100ms p95, 500 QPS, 10k zones) forecasting service needs pre-computed or cached predictions wherever possible (rather than computing a fresh forecast per request), an online feature store fast enough to serve the remaining real-time inputs within the latency budget, a model store supporting fast model loading/versioning, and explicit availability/rollback strategies given the operational stakes of a customer-facing latency SLA.
Structured elaboration
- Model store: hosts versioned, trained models ready for fast loading into the serving layer; at 10k zones, likely one (or a small number of clustered) GLOBAL models rather than 10k independently-loaded per-zone models, both for the same statistical pooling reasons that favor global models at scale and for the practical serving reason that loading 10k separate model artifacts per request path is operationally unworkable within a 100ms budget.
- Feature store, online features: the features needed at inference time (recent lag values, calendar features, any real-time exogenous signal) must be servable with very low latency - a dedicated online feature store (backed by a fast key-value store, not a query against a data warehouse) is standard here, since a warehouse query would blow the 100ms budget on its own.
- Caching: for a request pattern where many requests ask for the SAME zone's forecast within a short window (a very plausible pattern at 500 QPS across "only" 10k zones), caching a recently-computed forecast (invalidated on a schedule matching how often the underlying forecast is genuinely refreshed, e.g. every 15 minutes) avoids recomputing an identical answer repeatedly, and is often the single biggest lever for hitting a tight latency SLA without needing every request to hit the full model-inference path.
- Serving batched predictions: even for on-request serving, batching multiple zones' feature vectors into one model inference call (rather than one model call per zone) amortizes fixed per-call overhead and is usually meaningfully faster in aggregate than fully independent per-request inference, especially for a model architecture (e.g. a global gradient-boosted or neural model) that scales well with batch size.
- Availability and rollback: run multiple redundant serving instances behind a load balancer so a single instance failure doesn't violate the latency SLA for other requests; deploy new model versions via a canary (a small slice of traffic first) with automated rollback if the new version's latency or accuracy regresses, rather than a full instantaneous cutover.
Worked example
A concrete architecture: features refreshed into a fast online store on a schedule (e.g. every few minutes) rather than computed synchronously per-request; a background job pre-computes and caches each zone's forecast at the SAME refresh cadence; the actual request-serving path becomes largely a cache lookup (very fast, easily within 100ms even at 500 QPS) with a fallback to synchronous on-demand inference only for a cache miss (a zone whose forecast hasn't been pre-computed recently, ideally a rare case) - this architecture trades a small amount of freshness (forecasts are as fresh as the last refresh cycle, not literally real-time) for a much more reliable and cheaper latency profile than computing everything synchronously per request.
Trade-offs & pitfalls
The most consequential design trade-off here is freshness vs latency/cost: pure synchronous per-request inference gives the freshest possible forecast but is the most expensive and riskiest way to hit a tight SLA at this request volume; a pre-compute-and-cache architecture is cheaper and more reliably fast but serves a slightly staler forecast - the right balance depends on how much genuine value fresher-than-cache-refresh-cycle forecasts actually provide for THIS specific use case (per-zone 15-minute demand predictions), which is worth validating rather than assuming synchronous freshness is automatically worth its cost.
For intermittent demand across many SKUs, classic RMSE and MAPE perform poorly. Propose a set of evaluation metrics and modeling approaches (including Croston, TSB, and probabilistic methods) appropriate for intermittent data and explain how you would aggregate the metrics across SKUs for business reporting.
Sample Answer
Direct answer
For intermittent demand, RMSE and MAPE both perform poorly (MAPE is undefined at the many zero periods, and RMSE is dominated by the rare nonzero spikes rather than reflecting typical performance); use metrics designed for intermittent series (MASE against a seasonal-naive-of-zero baseline, or specialized metrics like the Periods-In-Stock accuracy), and modeling approaches purpose-built for lumpy, zero-heavy demand - Croston's method, TSB, or a probabilistic count model - rather than standard ARIMA/ETS.
Structured elaboration
- Why RMSE/MAPE fail here: MAPE divides by the actual value, which is frequently exactly zero in intermittent series, making the metric literally undefined for most periods; RMSE's squared-error penalty means the handful of large nonzero-demand spikes dominate the score entirely, effectively ignoring how well the model does on the much more common all-zero periods, which is often what actually matters operationally (avoiding both stockouts on the rare demand event AND excess holding cost during the many zero periods).
- Croston's method: separately estimates (a) the average SIZE of demand when it does occur and (b) the average INTERVAL between demand occurrences, then combines them into a forecast - rather than trying to smooth a series that's mostly zero, it decomposes the problem into "how much, when it happens" and "how often it happens."
- TSB (Teunter-Syntetos-Babai): a refinement of Croston that updates the demand-occurrence PROBABILITY every period (even zero-demand periods), rather than only updating on periods with actual demand as classic Croston does - this fixes a known bias in Croston's original formulation where the forecast doesn't decay during a long run of zeros, which can leave forecasts stale for slow-moving items.
- Modified Croston / ML alternatives: various bias-correction variants of Croston exist to address its known small-sample bias; ML alternatives (e.g. a classifier for "will demand occur this period" combined with a regressor for "how much, given it occurs") can incorporate additional features (promotions, seasonality) that classic Croston/TSB cannot.
- Probabilistic methods: rather than a single point forecast, model the full demand-count distribution directly - a zero-inflated Poisson or Negative Binomial regression (or a bootstrap/empirical distribution over historical demand-per-period) that returns P(demand = k) for each future period instead of just an expected value. This matters specifically because the decision an intermittent-demand forecast actually feeds (safety stock, reorder point, a target service level) is a tail-risk/stockout-probability question, not a point-accuracy question - a probabilistic model that outputs the full distribution supports that decision directly, where a Croston/TSB point forecast alone needs a separate, bolted-on distributional assumption to get there.
- Evaluation metrics for intermittent series: MASE (against a seasonal-naive baseline, since its denominator - the naive forecast's own error - remains well-defined even with many zeros) is a standard scale-independent choice; specialized metrics that directly weigh stockout risk and holding cost asymmetrically (rather than a symmetric error metric) are often more operationally meaningful, since under- and over-forecasting intermittent demand usually have very different real costs.
- Aggregating metrics across many SKUs for business reporting: report the DISTRIBUTION of per-SKU MASE (median, and the tail of poorly-performing SKUs) rather than a single blended average, since a single number obscures whether errors are broadly small or concentrated in a few problematic SKUs that need individual attention; volume- or value-weighting the aggregate additionally reflects business impact rather than treating every SKU equally regardless of size.
Worked example
A SKU with demand in only 30% of weeks (zero the other 70%) forecast with classic Croston would produce a constant, non-zero expected-demand-per-period estimate blending the "how much" and "how often" components - useful for driving an average reorder policy, but the TSB variant's per-period-updated occurrence probability would react faster if that SKU's demand frequency itself started trending down (e.g. a slow-moving item becoming even slower), which classic Croston's occurrence-only-updates-on-demand-periods formulation would be slower to reflect.
Trade-offs & pitfalls
Applying a standard ARIMA/ETS model to intermittent demand without recognizing the zero-heavy structure typically produces a forecast that's neither a good point estimate for typical (zero) periods nor useful for planning around the rare demand events - the model ends up representing neither case well. Always check the fraction of zero periods in a series before defaulting to a standard forecasting approach; a meaningful zero-fraction (rule of thumb: above roughly 30-40%) is the signal to switch to an intermittent-demand-specific method.
Unlock Full Question Bank
Get access to all Forecasting and Time-Series Analysis interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.