Data Science

Chapter 10
Time-Series, Forecasting and Prescriptive Analytics

Post Graduate Program in AI and ML
Data Science   •   Post Graduate

Time-Series, Forecasting and Prescriptive Analytics

Introduction and context

Many managerial and engineering decisions depend not only on the current value of a variable but also on its evolution through time. Electricity demand, product sales, website traffic, equipment vibration, inflation, hospital admissions and inventory levels are examples of time-series data. A time series is an ordered sequence of observations recorded at successive and usually equally spaced times. Its defining feature is that observations may be statistically dependent: yesterday’s demand can influence today’s demand, and a temperature measurement can be related to measurements several hours earlier.

Forecasting uses historical and external information to estimate future values or future probability distributions. Prescriptive analytics goes further. It combines forecasts with objectives, constraints, costs, risks and available actions to recommend what should be done. Thus, a forecast of high demand is descriptive or predictive; deciding how much to produce, where to allocate inventory and whether to purchase overtime capacity is prescriptive.

A reliable forecasting system is therefore not merely a model. It is a decision system consisting of data collection, temporal validation, model estimation, uncertainty quantification, monitoring and action selection.

Learning objectives

After studying this chapter, the reader should be able to:

  1. Decompose time series into trend, seasonality, cycles, irregular variation and dependence.
  2. Construct and interpret naïve, moving-average, exponential-smoothing, ARIMA and regression-based forecasts.
  3. Distinguish stationarity, autocorrelation, seasonality and non-stationarity.
  4. Design leakage-resistant temporal training and evaluation procedures.
  5. Measure forecast accuracy and produce prediction intervals.
  6. Explain how machine-learning models can use lagged, calendar and external variables.
  7. Integrate uncertain forecasts with simulation, optimization and resource-allocation decisions.
  8. Evaluate operational, ethical, governance and managerial consequences of forecasting systems.

1. The structure of temporal data

Let yt denote the observed value at time t, where the time index may represent hours, days, weeks, months or another regular interval. A forecasting task uses information available at a forecast origin T to estimate one or more future values yT+h, where h is the forecast horizon.

Important distinctions include:

  • Univariate forecasting: only past values of the target are used.
  • Multivariate or dynamic forecasting: target history is combined with predictors such as price, weather, promotions or macroeconomic variables.
  • One-step forecasting: h=1.
  • Multi-step forecasting: several future periods are predicted.
  • Nowcasting: estimating the current or very near-term value using incomplete, rapidly arriving data.
  • Exogenous variable: a predictor determined outside the target equation, or treated as externally supplied for forecasting purposes.
  • Forecast origin: the latest time at which information is assumed to be available.

A time series may contain several components. A useful conceptual representation is

yt = Tt + St + Ct + εt

where Tt is the trend, St is a seasonal component, Ct is a cyclical or medium-term component, and εt is irregular variation. This additive form is appropriate when seasonal amplitude is approximately constant. If seasonal fluctuations grow with the level, a multiplicative form is often more suitable:

yt = Tt × St × εt

The multiplicative model requires non-negative observations and is frequently transformed using logarithms. Under a logarithmic transformation, multiplication becomes addition: ln(yt)=ln(Tt)+ln(St)+ln(εt). Zero or negative observations require alternative treatments.

Trend is a persistent long-term direction, whereas seasonality is a repeating pattern with a known or stable period, such as seven days or twelve months. A cycle is a longer fluctuation whose duration is not necessarily fixed, often associated with economic conditions. Irregular variation includes shocks, measurement error and unmodeled effects.

2. Dependence and stationarity

Temporal dependence means that the joint distribution of observations changes or remains related across time. The lag-k autocovariance is

γk = Cov(yt, yt-k)

and the autocorrelation is

ρk = γk / γ0

where γ0=Var(yt). These quantities are formally defined for a weakly stationary process, in which the mean and variance are constant over time and covariance depends only on the lag, not on the calendar date. Sample autocorrelation is an estimate and can be misleading when trend or seasonality has not been removed.

A series with a changing level, changing variance or evolving seasonal pattern is non-stationary. Differencing can sometimes produce a stationary series:

∆yt = yt − yt−1

Seasonal differencing with period m is

∆m yt = yt − yt−m

Differencing should be used only when justified. Excessive differencing can create unnecessary noise and induce negative autocorrelation. Stationarity should be assessed using plots, domain knowledge, autocorrelation patterns and formal tests such as the augmented Dickey–Fuller test, while recognizing that tests have limited power and depend on their specification.

A white-noise process has zero mean, constant variance and no serial correlation. Forecast errors should ideally approximate white noise. Lack of autocorrelation does not prove that a model is correct, but significant residual dependence is evidence that useful temporal structure remains.

3. Forecasting workflow

A disciplined workflow contains the following stages.

Problem definition

Specify the decision, target variable, frequency, horizon, forecast origin, required granularity and acceptable error. A model for hourly staffing has different requirements from a model for annual capital expenditure.

Data construction

Use event time rather than data-arrival time where appropriate, preserve missingness information, correct time zones and daylight-saving changes, and record revisions to historical data. Duplicated timestamps, irregular intervals, sensor outages and changes in product definitions can invalidate otherwise sophisticated models.

Exploratory analysis

Plot the level, transformed level, rolling mean and rolling variance. Examine seasonal subseries, lag plots, autocorrelation and outliers. Separate genuine shocks from recording errors; an intervention should not silently overwrite an important event.

Temporal partitioning

Random train-test splitting is usually inappropriate because it allows future observations to influence training. Instead, use an initial training interval followed by a chronologically later validation or test interval. Rolling-origin evaluation repeatedly trains using data available at each origin and evaluates the next horizon.

Baselines

A baseline establishes whether complexity is justified. Common baselines are:

  • Naïve: ŷT+1=yT.
  • Seasonal naïve: ŷT+h=yT+h−m, when the seasonal period is m.
  • Mean forecast: historical mean, useful mainly for stationary series.
  • Drift forecast: extrapolates the average change between the first and latest observations.

Estimation, diagnosis and deployment

Fit candidate models, inspect residuals, compare them using temporal backtesting, quantify uncertainty, and deploy only with monitoring. A model should be retrained when data-generating conditions change, not merely according to a fixed calendar.

4. Classical forecasting methods

Moving averages

A simple moving-average forecast over the preceding k observations is

ŷt+1 = (1/k) ∑i=0k−1 yt−i

This smooths short-term noise but lags behind rapid trend changes and does not naturally represent seasonality. The observations must be on a comparable scale and equally spaced for the standard formula.

Exponential smoothing

Simple exponential smoothing assigns greater weight to recent observations:

ℓt = αyt + (1−α)ℓt−1

where 0<α<1 is the smoothing parameter and ℓt is the level. For a series without trend or seasonality, the forecast from time t for any future horizon is ŷt+h|t=ℓt. Initial level selection affects short series; common choices include the first observation or an estimated value.

Holt’s method adds a trend. One common additive form is

ℓt = αyt + (1−α)(ℓt−1+bt−1)
bt = β(ℓt−ℓt−1) + (1−β)bt−1
ŷt+h|t = ℓt + hbt

Here bt is the estimated trend and 0<β<1. Damped-trend methods reduce implausibly large long-range extrapolation by gradually weakening the trend.

Holt–Winters methods add seasonality. With additive seasonality and period m, one standard formulation is

ℓt = α(yt−st−m) + (1−α)(ℓt−1+bt−1)
bt = β(ℓt−ℓt−1) + (1−β)bt−1
st = γ(yt−ℓt) + (1−γ)st−m
ŷt+h|t=ℓt+hbt+st−m+1+((h−1) mod m)

where 0<γ<1 is the seasonal smoothing parameter. Implementations differ in initialization and indexing conventions; the chosen formulation must be documented. Multiplicative seasonality replaces additive seasonal effects with ratios and requires suitable positive data.

5. ARIMA and regression models

An autoregressive model of order p is

yt = c + φ1yt−1+⋯+φpyt−p+εt

where c is an intercept, φi are autoregressive coefficients and εt is an innovation. Stationarity imposes restrictions on the coefficients; for an AR(1), yt=c+φyt−1+εt, a sufficient and necessary condition for weak stationarity is |φ|<1.

A moving-average model of order q is

yt = μ + εt + θ1εt−1+⋯+θqεt−q

An ARIMA(p,d,q) model applies d differences before modeling the resulting series with AR and MA terms. Seasonal ARIMA, written SARIMA, adds seasonal autoregressive, differencing and moving-average terms for period m. Model orders are commonly guided by domain knowledge, autocorrelation and partial autocorrelation, information criteria, and rolling-origin performance. Information criteria reward fit but penalize complexity; they do not replace out-of-sample evaluation.

Regression with temporal errors is useful when causal or operational drivers are available:

yt = β0 + β1x1,t+⋯+βpxp,t+nt

where nt may follow an ARIMA process. Lagged target variables, distributed lags, calendar indicators and interactions can capture delayed effects. A predictor must be known at forecast time or itself forecasted. Using a future promotion, revised weather observation or post-outcome variable creates leakage.

6. Machine-learning forecasting

Machine-learning forecasting converts temporal structure into supervised-learning features. A feature vector may contain

Xt = [yt−1, yt−7, yt−28, rollingmeant−1, promotiont, temperaturet, weekdayt]

The target may be yt+h or a vector of several horizons. Suitable algorithms include regularized linear regression, random forests, gradient-boosted trees, support-vector regression and neural networks. Long short-term memory networks and temporal convolutional networks can represent complex sequences, while transformers may model long-range dependencies, especially with large datasets and many related series.

Feature engineering remains essential. Calendar variables can be represented by one-hot encoding or cyclic encoding. For a seasonal period m, cyclic features are

sin(2πt/m), cos(2πt/m)

These preserve the fact that the end and beginning of a cycle are close. Lagged features must be shifted so that only information available at the origin is used. Scaling, imputation and feature selection must be fitted within each training fold in temporal cross-validation.

Direct multi-horizon forecasting fits a separate model for each horizon. Recursive forecasting fits one-step models and feeds predictions back as future inputs. Direct methods avoid accumulated recursive error but require more models; recursive methods are simpler but can propagate errors. Multi-output models estimate all horizons jointly.

Machine learning is especially useful when nonlinear effects, many predictors, hierarchical relationships or large collections of related series exist. It is not automatically superior to classical methods. On short, noisy or strongly seasonal series, exponential smoothing or seasonal naïve forecasts may be harder to beat and easier to explain.

7. Forecast accuracy and uncertainty

Let yi be an observed value and ŷi its forecast over n evaluation cases. Mean absolute error is

MAE = (1/n) ∑|yi−ŷi|

It has the same units as the target and is interpretable as average absolute error. Root mean squared error is

RMSE = √[(1/n)∑(yi−ŷi)2]

RMSE penalizes large errors more strongly. Mean absolute percentage error is

MAPE = (100/n)∑ |(yi−ŷi)/yi|

and is undefined when yi=0, unstable near zero and often unsuitable for intermittent demand. Weighted or scaled measures can be preferable. Mean absolute scaled error compares forecast error with the in-sample naïve error; its exact denominator must match the seasonal structure and evaluation design.

Accuracy should be assessed at the decision-relevant horizon and aggregation level. A model can have good average accuracy but systematically underforecast peaks, which may be unacceptable for capacity planning. Bias can be examined through mean error:

ME = (1/n)∑(yi−ŷi)

Prediction intervals quantify uncertainty. A central 100(1−α)% interval is intended to contain the future observation with probability approximately 1−α, under the model and calibration assumptions. Forecast intervals widen with horizon because uncertainty accumulates. They may be obtained from analytical error distributions, bootstrap residuals, simulation, quantile regression or conformal prediction. A point forecast without an interval can encourage false precision.

Probabilistic forecasts should be evaluated with proper scoring rules. The interval score for an interval [[MATH#[L,U]]] at nominal miscoverage α is

IS_α = (U−L) + (2/α)(L−y)I(y<L) + (2/α)(y−U)I(y>U)

where I(·) equals 1 when its condition is true and 0 otherwise. The score rewards narrow intervals but penalizes failures to cover observations. Calibration asks whether stated probabilities match observed frequencies; sharpness asks whether distributions are concentrated, subject to calibration.

8. From forecasts to prescriptions

Prescriptive analytics represents decisions explicitly. Let x be a decision vector, ξ uncertain future demand, c costs and 𝒳 the feasible set. A stochastic optimization problem is

minx∈𝒳 E_ξ[C(x,ξ)]

The expectation is taken over the forecast distribution. Decisions may include production, staffing, inventory, transportation, cloud capacity or maintenance timing. Constraints may represent labor, budget, service-level, storage, safety or regulatory limits.

A simple single-period inventory problem illustrates the connection. Let demand D be uncertain, unit purchase cost be c, shortage penalty be p, and excess-unit cost be h. The expected cost of ordering Q is

E[C(Q,D)] = cQ + pE[(D−Q)^+] + hE[(Q−D)^+]

where z^+=max(z,0). If the purchase cost is already included in the overage and underage definitions, it should not be double-counted. In the classical newsvendor formulation, the critical fractile is

P(D≤Q*) = p/(p+h)

where p is the underage cost and h is the overage cost. Thus Q* is the corresponding demand quantile. The formula assumes a single decision period, known cost parameters, no replenishment during the period and a continuous or appropriately discretized demand distribution.

Simulation is useful when the operational system is too complex for a closed-form solution. Draw scenarios from the forecast distribution, apply each candidate policy, calculate costs and service outcomes, and compare distributions rather than only expected values. Monte Carlo estimates become more stable as the number of scenarios increases, but scenario quality matters more than arbitrary scenario quantity.

Robust optimization protects against forecast misspecification by optimizing against a set of plausible distributions or parameter values. Chance constraints impose probabilistic service requirements, such as

P(g(x,ξ)≤0) ≥ 1−α

where g represents a constraint violation and α is the tolerated violation probability. Such constraints require a valid probability model or conservative approximation.

Forecast reconciliation is important in hierarchical systems. Store-level forecasts should be coherent with regional and national totals. Reconciliation methods adjust base forecasts so that aggregation relationships hold, while considering forecast error covariance and operational priorities.

9. Detailed illustrative case: hospital staffing

Background. A fictional metropolitan hospital schedules emergency-department nurses in hourly blocks. Arrivals exhibit strong hour-of-day and day-of-week patterns, while weather, public holidays and local events affect demand.

Problem. Managers currently schedule from the previous week’s arrivals. This causes understaffing during surges and excessive idle capacity during quiet periods. The hospital wants forecasts for the next 24 hours, prediction intervals and a staffing recommendation that respects labor rules.

Analysis. The data team audits timestamps, removes duplicate records, distinguishes arrival time from triage-completion time and marks unusually low counts caused by a registration-system outage. Exploratory plots reveal daily and weekly seasonality. The team uses a seasonal naïve baseline, dynamic regression with calendar and weather variables, and a gradient-boosted model with lagged arrivals and rolling summaries. Weather forecasts, rather than realized future weather, are used in historical backtests to reproduce deployment conditions.

Approach and solution. The last twelve weeks are reserved as a rolling-origin test period. Each model is retrained at each origin. The selected model is not the one with the lowest overall RMSE alone: it must also provide calibrated upper prediction intervals because understaffing is more costly than moderate overstaffing. Forecast scenarios are passed to a mixed-integer staffing model. Decision variables include the number of regular nurses, float nurses and overtime assignments. Constraints enforce minimum coverage by hour, maximum consecutive shifts, skill mix and labor-law requirements. A penalty is assigned to unmet demand and a separate cost to overtime.

For each simulated demand scenario, the staffing policy produces waiting-time and cost outcomes. Managers choose a policy on a cost–service frontier rather than accepting the mathematically cheapest plan. The system displays the point forecast, an interval, the principal drivers and the consequences of staffing at several risk levels.

Outcome. In this illustrative case, backtesting shows that the dynamic regression improves peak-hour performance over the seasonal naïve baseline, while the boosted model performs best only when sufficient recent data are available. The hospital adopts a model ensemble with a conservative upper-tail adjustment during major events. It monitors forecast bias, interval coverage, waiting time, overtime and fairness across shifts.

Learning points. The case demonstrates that (1) data definitions can matter more than model choice; (2) evaluation must reproduce information available at deployment; (3) uncertainty is essential when shortage costs are asymmetric; (4) the best forecast does not automatically yield the best staffing decision; and (5) human oversight is necessary when operational constraints and patient safety are involved.

10. Challenges, governance and responsible use

Data leakage and revision. Future information may enter through improperly aligned features, post-event corrections or random cross-validation. Every feature should have a documented availability timestamp.

Concept drift. Consumer behavior, policies, climate, competition and technology change. Drift monitoring should examine both input distributions and forecast residuals. Retraining frequency should reflect the speed and cost of change.

Intermittent and hierarchical demand. Sparse demand may require Croston-type methods, count models or carefully designed machine-learning approaches. Aggregating first can hide local operational variation.

Structural breaks and shocks. Pandemics, strikes and regulatory changes can invalidate historical relationships. Interventions, scenario analysis and human judgment may be more appropriate than blind extrapolation.

Fairness. Forecasts used to allocate health resources, policing, credit or social services can reproduce historical inequities. Accuracy should be examined across relevant groups, and decisions should be audited for disparate impact. A forecast is not a justification for discriminatory action.

Privacy and security. Temporal records may reveal attendance, mobility, health status or household behavior. Data minimization, access control, retention limits, encryption and appropriate anonymization are essential. Models should be protected against manipulation of timestamps and input streams.

Explainability and accountability. Decision makers need to know the forecast horizon, uncertainty, major drivers, limitations and escalation procedure. Model cards, data sheets, versioned code, reproducible experiments and audit logs support accountability. Automated recommendations should have an identified owner and a safe override process.

Contemporary developments. Probabilistic deep learning, foundation models for time series, global models trained across many related series, conformal prediction, causal forecasting and differentiable optimization are active research areas. Their adoption should be justified by demonstrated improvement, computational feasibility, calibration and governance—not novelty alone. Causal forecasting requires an explicit causal design; predictive association does not establish that changing a variable will produce the predicted outcome.

Best-practice checklist

  1. Define the decision and horizon before choosing a model.
  2. Establish naïve and seasonal-naïve baselines.
  3. Preserve time order in every validation operation.
  4. Align every feature with its real availability time.
  5. Diagnose trend, seasonality, dependence, missingness and breaks.
  6. Evaluate both point accuracy and probabilistic calibration.
  7. Match the loss function to operational consequences.
  8. Use scenarios or distributions when decisions are sensitive to uncertainty.
  9. Test policies, not only forecasts, in simulation or backtesting.
  10. Monitor drift, bias, service outcomes and human overrides after deployment.

Chapter Summary

Time-series analysis models observations indexed by time, emphasizing trend, seasonality, cycles, irregular variation and serial dependence. Decomposition, differencing and autocorrelation help diagnose structure and stationarity. Classical methods—including moving averages, exponential smoothing, Holt–Winters and ARIMA—remain strong, interpretable baselines. Regression and machine-learning methods extend forecasting through external variables, nonlinearities and large collections of related series, but they require leakage-resistant temporal validation.

Forecast evaluation should use decision-relevant horizons, suitable metrics and calibrated prediction intervals. Point forecasts alone conceal risk. Prescriptive analytics transforms forecast distributions into actions through optimization, simulation, chance constraints, robust methods and hierarchical reconciliation. The illustrative hospital case shows that data quality, asymmetric costs, operational constraints and governance are as important as algorithm selection. Responsible deployment requires attention to drift, privacy, fairness, interpretability, accountability and safe human oversight.

Key Terms

Time series: Ordered observations indexed by time.

Forecast origin: Latest time at which information is assumed available for a forecast.

Horizon: Number of future periods being forecast.

Trend: Persistent long-term direction in a series.

Seasonality: Repeating pattern with a stable calendar or time period.

Cycle: Longer fluctuation whose duration is not necessarily fixed.

Stationarity: Stability of relevant distributional properties over time.

Autocorrelation: Correlation between observations separated by a specified lag.

Differencing: Subtracting a prior observation to reduce non-stationarity.

White noise: Uncorrelated random variation with stable mean and variance.

Exponential smoothing: Forecasting family that weights recent observations more heavily.

ARIMA: Autoregressive integrated moving-average model.

Exogenous variable: External predictor used in a forecasting model.

Data leakage: Use of information unavailable at the forecast origin.

Rolling-origin evaluation: Repeated chronological training and testing procedure.

Prediction interval: Range intended to contain a future observation at a stated probability.

Calibration: Agreement between stated predictive probabilities and observed frequencies.

Prescriptive analytics: Use of predictions, objectives and constraints to recommend actions.

Scenario simulation: Evaluation of policies under generated possible futures.

Concept drift: Change in the data-generating process over time.

Review Questions

Short Answer Questions

  1. Distinguish trend, seasonality and cyclical variation.
  2. Why is random train-test splitting usually inappropriate for time-series forecasting?
  3. State the difference between a point forecast and a prediction interval.
  4. What is data leakage? Give one temporal example.
  5. Why might a seasonal-naïve model be a useful baseline?

Long Answer Questions

  1. Explain the forecasting workflow from problem definition through deployment and monitoring.
  2. Compare simple exponential smoothing, Holt’s method, Holt–Winters methods and ARIMA.
  3. Discuss how lagged and calendar features are constructed for machine-learning forecasting.
  4. Explain why forecast accuracy and forecast calibration are distinct properties.
  5. Describe how stochastic optimization connects a forecast distribution to an operational decision.

Analytical / Application Questions

  1. A retailer has weekly demand with a strong annual pattern and intermittent promotions. Design a temporal validation strategy, propose baseline and advanced models, and identify which promotion variables can legitimately be used.
  2. A hospital must choose staffing with high shortage costs and limited overtime. Explain how prediction intervals, scenario simulation and a constrained optimization model could be combined.
  3. A forecasting model has lower RMSE than its competitor but systematically underestimates peak demand. Determine whether it should be deployed for capacity planning and specify the additional analyses required.

Multiple Choice Questions with Answers

Question 1

Which statement best describes a forecast origin?

A. The first observation in a dataset

B. The latest time at which information is assumed available

C. The time at which a model was programmed

D. The average time between observations

Correct Answer: B. The latest time at which information is assumed available

Question 2

For a stationary AR(1) process yt=c+φyt−1+εt, which condition ensures weak stationarity?

A. φ=0

B. φ>1

C. |φ|<1

D. φ<−1

Correct Answer: C. |φ|<1

Question 3

Which metric has the same units as the target variable?

A. MAE

B. MAPE

C. A correlation coefficient

D. A percentage error

Correct Answer: A. MAE

Question 4

Why can MAPE be unsuitable for intermittent demand?

A. It cannot compare forecasts

B. It is undefined when actual demand is zero

C. It always penalizes underforecasting more

D. It has squared units

Correct Answer: B. It is undefined when actual demand is zero

Question 5

In simple exponential smoothing, what does α control?

A. The seasonal period

B. The number of regressors

C. The weight assigned to the current observation

D. The forecast horizon

Correct Answer: C. The weight assigned to the current observation

Question 6

Which practice prevents a common form of temporal leakage?

A. Randomly shuffling all observations

B. Using future realized weather in historical backtests

C. Fitting preprocessing only on data available in each training fold

D. Replacing all missing values with future averages

Correct Answer: C. Fitting preprocessing only on data available in each training fold

Question 7

A seasonal-naïve forecast for period m uses which value for forecasting y_{T+h}?

A. The overall sample mean

B. The observation y_{T+h−m}

C. The most recent first difference

D. The largest historical observation

Correct Answer: B. The observation y_{T+h−m}

Question 8

What is the principal purpose of a prediction interval?

A. To guarantee the future value

B. To describe uncertainty about a future observation

C. To eliminate residual errors

D. To rank feature importance

Correct Answer: B. To describe uncertainty about a future observation

Question 9

In the classical newsvendor model with underage cost p and overage cost h, the optimal order quantity satisfies which condition?

A. P(D≤Q*)=h/(p+h)

B. P(D≤Q*)=p/(p+h)

C. P(D≤Q*)=p−h

D. P(D≤Q*)=p×h

Correct Answer: B. P(D≤Q*)=p/(p+h)

Question 10

What is concept drift?

A. A fixed seasonal pattern

B. A change in the data-generating process over time

C. A method for calculating RMSE

D. A constraint in linear programming

Correct Answer: B. A change in the data-generating process over time

Data Science
Chapter 10 of 15