Interview's MateData Science
Interview's Mate

Data Science

Python → ML → MLOps

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Data Science topics
Lesson 100/ 160
05. Classical Machine Learning

Time-Series Forecasting (ARIMA, SARIMA, Prophet)

Forecast with classical ARIMA family models and Prophet-style seasonality components.

AdvancedARIMA · SARIMA3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

Forecasting models look at how a number moved in the past, including its trend, repeating weekly or yearly patterns and special days, and project that forward with a range of uncertainty.

Think of it like…

Weather forecasting from yesterday's weather and the season: ARIMA learns how today depends on recent days and recent forecast errors, Prophet separately models the long-term warming trend, the yearly and weekly cycles and special days like holidays.

Where you’ve seen it

An AR(1) model y_t = 0.7 y_{t−1} + ε_t with last value y_T = 10 (mean 0) forecasts 7.0 for h = 1, 4.9 for h = 2 and 3.43 for h = 3, since ŷ_{T+h} = φ^h y_T decays toward the mean. Forecast uncertainty grows: the variance is σ²(1 − φ^{2h}) / (1 − φ²), so the standard deviation is σ at h = 1, 1.32σ at h = 3 and approaches 1.40σ at long horizons. For daily sales with a weekly cycle the analyst first checks stationarity (ADF test), takes a first difference (d = 1) and a seasonal difference (D = 1, m = 7), reads the ACF and PACF to choose orders and compares candidates by AIC, ending with SARIMA(1,1,1)(0,1,1)₇. Prophet is configured with a yearly Fourier order of 10 (20 parameters), weekly order 3 (6 parameters), US holidays and 25 potential changepoints. A seasonal-naive baseline (same weekday last week) has MAE 15; SARIMA gets MAE 12 and Prophet 11.5, so MASE = 12 / 15 = 0.80 and 0.77, both better than the baseline, evaluated on 6 rolling origins with a 28-day horizon.

Words you’ll hear

Stationarity
Constant mean, variance and autocorrelation over time; required by ARMA models.
Differencing
Subtracting the previous value (or the value one season earlier) to remove trend or seasonality.
ACF / PACF
Autocorrelation functions whose cut-off patterns suggest MA and AR orders.
MASE
Mean absolute error scaled by that of a naive forecast; below 1 beats the naive baseline.

Visual diagram

Loading interactive diagram

Theory & deep dive

ARIMA and SARIMA

ARMA models assume a stationary series. If there's trend or seasonality, difference it: first difference yₜ − yₜ₋₁ removes a linear trend (d = 1); seasonal difference yₜ − yₜ₋ₘ removes a fixed seasonal pattern (D = 1, m = 7 for daily data with a weekly cycle). Check with a plot and the ADF (or KPSS) test. The AR(p) part says yₜ = c + φ₁yₜ₋₁ + ... + φₚyₜ₋ₚ + εₜ; MA(q) says the series depends on past shocks. Reading ACF/PACF of the differenced series: an AR(p) process has a PACF that cuts off after lag p and a decaying ACF; an MA(q) has an ACF that cuts off after lag q. In practice, search a small grid of orders and compare by AIC/BIC and out-of-sample error (statsmodels SARIMAX, or pmdarima.auto_arima).

A worked AR(1): y_t = 0.7 y_{t−1} + ε, last value 10 → forecasts 7.0, 4.9, 3.43, converging to the mean 0 as φ^h → 0. The forecast variance grows as σ²(1 − φ^{2h}) / (1 − φ²): the standard error is σ at h = 1, 1.32σ at h = 3 and tends to 1.40σ, which gives widening prediction intervals. After fitting, check residuals: they should look like white noise (no autocorrelation: Ljung-Box test, ACF of residuals within bands, roughly constant variance). Seasonal ARIMA multiplies in seasonal terms with period m; for multiple seasonalities (daily data with weekly and yearly cycles), add Fourier terms as exogenous regressors (SARIMAX with exog), or use Prophet, TBATS or ETS-style models. Exogenous variables (price, promotion) enter as regressors.

AR(1) forecast

φ = 0.7, y_T = 10, mean 0. ŷ_{T+1} = 7.0, ŷ_{T+2} = 4.9, ŷ_{T+3} = 3.43. Standard error multipliers: h = 1 → 1.00σ, h = 3 → √((1 − 0.7⁶)/(1 − 0.49)) = √1.730 = 1.32σ, limit √(1/0.51) = 1.40σ.

Key takeaway: Difference to stationarity, read ACF/PACF, select by AIC and out-of-sample error and check residuals for white noise.

Prophet, validation and metrics

Prophet fits y(t) = g(t) + s(t) + h(t) + ε. The trend g(t) is piecewise linear (or saturating logistic) with automatically placed changepoints (default 25 over the first 80% of the history, with a sparse prior controlling flexibility through changepoint_prior_scale). Seasonality s(t) is a Fourier series (default order 10 for yearly = 20 parameters, 3 for weekly = 6) with additive or multiplicative mode (seasonality_mode="multiplicative" when seasonal swings scale with level). Holidays are listed with windows. It tolerates missing days and outliers, needs minimal tuning and gives interpretable components, but it is not always more accurate than well-specified ARIMA or ETS, and it doesn't model short-term autocorrelation, so evaluate it against alternatives.

Validate forward in time: rolling-origin cross-validation (train on an initial window, forecast the next horizon, roll forward, repeat; TimeSeriesSplit, Prophet's cross_validation) rather than a random split. Choose metrics carefully: MAE and RMSE in the target's units, MAPE (fails at zeros, biased toward under-forecasting), sMAPE, and MASE = MAE / MAE of a naive forecast, which is scale-free and interpretable (below 1 beats the baseline: 12 / 15 = 0.80). Always include a seasonal-naive (and plain naive) baseline: if a model can't beat it, don't ship it. Report prediction intervals and check their coverage on backtests (do 80% intervals contain about 80% of actuals?). For production: retrain on a schedule, monitor forecast error and bias, handle holidays and promotions as inputs, reconcile hierarchical forecasts (store, region, total) and allow human overrides for known events.

MASE

Seasonal-naive MAE 15 over six rolling origins. SARIMA MAE 12 → MASE 0.80. Prophet MAE 11.5 → MASE 0.77. Both beat the baseline; an 80% prediction interval covered 78% of actuals for SARIMA and 84% for Prophet, close to the nominal level.

Key takeaway: Use rolling-origin validation, compare against seasonal naive with MASE, and check interval coverage.

How it works, step by step

Step 1 of 4
Analyst

1. Explore and baseline

Plot, decompose, check gaps and outliers and set seasonal-naive and naive baselines.

seasonal naive MAE 15
Key numbers at this step
Holidays
list them

When to use it & trade-offs

What it is

ARIMA(p, d, q) forecasts a series from its own past: AR(p) terms regress on p previous values, I(d) differences the series d times to remove trend and make it stationary, and MA(q) terms use q past forecast errors. SARIMA adds seasonal AR, differencing and MA terms with period m (for example m = 7 for weekly cycles in daily data). Prophet takes a different, decomposable approach: y(t) = trend g(t) (piecewise linear or logistic with changepoints) + seasonality s(t) (Fourier series) + holiday effects h(t) + noise, fitted with Bayesian-style regularisation and designed to be easy to configure for business series with strong seasonality and missing data. Both are judged by out-of-sample accuracy on a proper rolling-origin evaluation against simple baselines.

Why it matters: Forecasts drive inventory, staffing, budgets and capacity. Time-series data breaks the usual ML assumptions (observations are dependent, order matters, distributions drift), so random splits, plain R² and naive features mislead. Knowing stationarity, differencing, ACF/PACF reading, the structure of Prophet and the right validation scheme lets you produce forecasts with honest uncertainty and a baseline to beat.

When to reach for it

  • Demand, traffic and revenue forecasting
  • Capacity and inventory planning
  • Budgeting with prediction intervals

When to avoid or be careful

  • Random train-test splits on time series
  • Reporting MAPE on series with zeros
  • Shipping a model that can't beat seasonal naive

Forecasting methods

Seasonal naive and ETS
Best for: Strong baselines and simple seasonal series

Strengths: Fast, hard to beat on many series.

Watch out: Limited for complex drivers.

ARIMA / SARIMA(X)
Best for: Autocorrelated series with clear structure and exogenous inputs

Strengths: Principled, interval estimates, widely understood.

Watch out: Needs stationarity and order selection; one seasonality.

Prophet
Best for: Business series with trend changes, multiple seasonalities and holidays

Strengths: Easy to configure; interpretable components; handles gaps.

Watch out: Not always more accurate; ignores short-term autocorrelation.

Interview signals & numbers to know

When this topic comes up

  • “Forecast next quarter's demand”
  • Stationarity and differencing
  • ACF and PACF
  • Prophet changepoints
  • Rolling-origin validation

Benchmarks & rules of thumb

φ^h × y_T -
AR(1) forecast: 7.0, 4.9, 3.43
1.00σ → 1.32σ → 1.40σ -
forecast standard error at h = 1, 3, ∞ (φ = 0.7)
MASE = 12 / 15 = 0.80 -
scaled error versus the seasonal-naive baseline

Common mistakes & follow-ups

Common interview mistakes

  • Differencing too much and creating artificial negative autocorrelation.
  • Selecting hyperparameters on a single holdout period.
  • Ignoring that intervals widen with the horizon.

Likely interviewer follow-ups

  • How do you make a series stationary?
  • How would you validate a forecasting model?
  • When would you choose Prophet over ARIMA?
Interview tip: Always mention a seasonal-naive baseline and MASE. It shows you judge forecasts against a meaningful benchmark.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Time-Series Forecasting (ARIMA, SARIMA, Prophet) with data science interview Q&A and hands-on practice.

Open Data Science Q&A →Machine Learning Q&A
Previous topic
Recommendation Systems (Collaborative & Content-Based)
Next topic
Missing Value Imputation Strategies