Time series in engineering
A time series is a sequence of measurements indexed by time. Its behaviour usually combines a trend, a slow change of level; seasonality, a pattern that repeats with a fixed period such as a day or a year; cycles without a fixed period; and irregular noise. Neighbouring values are correlated, which is the property forecasting exploits and the property that breaks the independence assumption of the random splits used in Weeks 7 and 8. Box and Jenkins built a systematic methodology on autocorrelation and differencing [1], and Hyndman and Athanasopoulos give a modern, practical account of forecasting with open examples [2].
The Keeling curve is a textbook series. Continuous measurements at Mauna Loa since 1958 show the carbon dioxide concentration rising every year, with an annual cycle of a few parts per million caused by the growth and decay of vegetation in the northern hemisphere [3, 4]. The rise itself accelerates, so a straight line underestimates the future.
Check your understanding. Why must the test set of a forecasting problem lie after the training period?
Formulas: Components, differences and autocorrelation
A time series is often described as the sum of a trend , a seasonal component that repeats with the period , for example for monthly data with a yearly cycle, and a remainder [2]:
When the seasonal swings grow with the level, a product fits better, and taking logarithms turns it into a sum. Differences remove a trend or a season:
The autocorrelation at lag measures how strongly the series is correlated with itself steps earlier. With the mean of the series [1]:
For a series without any autocorrelation, about 95% of the values lie between and [2]. A seasonal series has large values of at multiples of the period, and a trending series has values that decrease slowly with .
Worked example: Autocorrelation of a quarterly series
The electricity demand of a small plant, in MWh per quarter over two years, is 52, 40, 45, 60, 56, 43, 48 and 64.
Step 1. Mean and deviations. The mean is . The table lists the deviations , their squares and the products of each deviation with the deviation one, two and four quarters earlier:
| 1 | 52 | 1 | 1 | |||
| 2 | 40 | −11 | 121 | −11 | ||
| 3 | 45 | −6 | 36 | 66 | −6 | |
| 4 | 60 | 9 | 81 | −54 | −99 | |
| 5 | 56 | 5 | 25 | 45 | −30 | 5 |
| 6 | 43 | −8 | 64 | −40 | −72 | 88 |
| 7 | 48 | −3 | 9 | 24 | −15 | 18 |
| 8 | 64 | 13 | 169 | −39 | −104 | 117 |
| Sum | 408 | 0 | 506 | −9 | −326 | 228 |
Step 2. Lag 1. The seven products of neighbouring deviations add up to −9:
Step 3. Lag 2. The six products add up to −326:
Step 4. Lag 4. The four products add up to 228:
Step 5. Reading the values. The positive shows the yearly pattern: Each quarter resembles the same quarter a year earlier. The strongly negative shows that quarters half a year apart lie on opposite sides of the mean. With only eight values, the band is wide, so such conclusions need longer records. The seasonal differences are 4, 3, 3, 4, nearly constant, which reveals a trend of about 3.5 MWh per year that the season had hidden. Part A of the interactive lab computes autocorrelations and differences of any series.
Baselines and honest evaluation
Every forecasting study needs baselines. The naive forecast repeats the last observation, and the seasonal naive forecast repeats the value from one season earlier, for example the same month of the previous year [2]. A sophisticated model that cannot beat them has learned nothing useful. Evaluation must respect time: The model is trained on data up to a forecast origin and tested on the following horizon. Rolling-origin evaluation repeats this for several origins and averages the errors, which gives a more reliable picture than a single split. Errors grow with the horizon, so results should be reported per horizon or for the horizon that matters for the decision, such as one day ahead for unit commitment in a power system [5].
Animation: From a series to training examples
A window of past values forms the input and the next values form the target. Sliding the window through the training period creates the examples on which a model is trained. Change the window and horizon lengths.
Formulas: Baselines and error measures
A forecast made at the origin for the horizon is written . The naive forecast repeats the last observation, the seasonal naive forecast repeats the observation of the same season one period earlier, here for horizons up to one period, and the drift method extends the average change of the past [2]:
With the errors of the test values, the common error measures are
MAE is in the unit of the data, RMSE weighs large errors more, and MAPE is a percentage that fails when values come close to zero. The mean absolute scaled error divides the MAE by the in-sample MAE of the seasonal naive forecast on the training data, so that values below 1 beat that baseline [2]:
Rolling-origin evaluation repeats the forecast for several origins and averages the errors for each horizon.
Worked example: Three baselines and four error measures
The two years of quarterly demand of the previous example form the training data, and the third year, with 59, 47, 51 and 68 MWh, is the test period.
Step 1. Forecasts and errors. The naive forecast repeats the last value, 64. The seasonal naive forecast repeats the four quarters of the second year. A seasonal naive forecast with drift adds the mean yearly change of the training data, the mean of the seasonal differences 4, 3, 3 and 4, which is :
| Method | Forecasts | Errors |
|---|---|---|
| Naive | 64, 64, 64, 64 | −5, −17, −13, 4 |
| Seasonal naive | 56, 43, 48, 64 | 3, 4, 3, 4 |
| Seasonal naive with drift | 59.5, 46.5, 51.5, 67.5 | −0.5, 0.5, −0.5, 0.5 |
Step 2. MAE and RMSE.
and for the forecast with drift every error has the size 0.5, so its MAE and RMSE are both 0.5.
Step 3. MAPE. For the naive forecast, the relative errors are , , and :
The same computation gives 6.34% for the seasonal naive forecast and 0.9067% with drift.
Step 4. MASE. The in-sample seasonal naive errors of the training data are 4, 3, 3 and 4, with the mean 3.5, so the MASE is for the naive forecast, for the seasonal naive forecast and with drift. Only the forecast that respects both season and trend beats the seasonal naive baseline clearly. Part B of the interactive lab computes all baselines and measures for any series. Part C compares the naive, seasonal naive, moving average, trend-and-season regression and Holt-Winters forecasts of a generated series on a held-out final period, and Part D repeats the comparison over rolling origins and shows how the error grows with the horizon.
Regression models for time series
Linear regression becomes a forecasting model when its inputs describe time. A polynomial trend captures slow change, and pairs of sine and cosine terms with the seasonal period, called Fourier terms, capture a smooth seasonal pattern with few parameters. Lagged values of the series itself, the value one month ago or twelve months ago, turn forecasting into ordinary supervised learning, so that ridge regression, random forests or gradient boosting can be used. For horizons longer than one step, the model is applied recursively, feeding its own forecasts back as lags, or a separate model is trained for each horizon. Exponential smoothing and ARIMA models are classical alternatives with well understood behaviour and prediction intervals [1, 2].
Check your understanding. A monthly series has a yearly cycle. Which pair of features represents the first harmonic of the season?
Formulas: Trend and Fourier terms, autoregression and exponential smoothing
A regression on time describes the trend by powers of and a season of period by pairs of sine and cosine terms, the Fourier terms [2]:
The pair of order describes one smooth wave per period. Since with , the pair has the amplitude , and its phase sets the season of the peak; higher orders sharpen the shape.
An autoregression predicts a value from the values before it, which turns forecasting into ordinary regression on lagged inputs [1]:
For , least squares on the pairs gives and , with
for the pairs. Forecasts for several steps use earlier forecasts as inputs, recursively. For they approach the mean geometrically, since .
Exponential smoothing forms a level as a weighted average of the newest value and the previous level, with a smoothing factor ; unrolled, the weights of the past values decay geometrically. Holt's method adds a trend with its own factor [2]:
Without the trend, , this is simple exponential smoothing, whose forecast is the last level for every horizon. The Holt-Winters method adds a third equation for the seasonal component.
Worked example: Fourier terms of a monthly cycle
A model of a monthly carbon dioxide record contains the first Fourier pair with the illustrative coefficients and ppm. Time is counted in months from January, so that the terms with depend only on the month of the year.
Step 1. The features of May and November. For May, is 150 degrees, so and . For November, 330 degrees give and . The seasonal terms are
Step 2. Amplitude. ppm, which agrees with the value of May up to rounding. The seasonal term therefore peaks in May at the value and reaches its trough, , six months later in November, as the vegetation of the northern hemisphere takes up carbon dioxide in summer [3].
Step 3. A prediction. With a level of 420 ppm in January and a trend of 0.2 ppm per month, the model predicts for May of the same year ppm.
Worked example: An autoregression fitted by hand
A sensor gives the readings 20, 23, 22, 25, 24, 26 and 25. An autoregression of order 1 uses the six pairs (20, 23), (23, 22), (22, 25), (25, 24), (24, 26) and (26, 25).
Step 1. Sums. , , , and
Step 2. Least squares.
Step 3. Recursive forecasts. From the last reading, 25, and with the exact value :
Step 4. The long run. The mean is . The distance of the forecasts from it shrinks by the factor 2/7 per step, from to , which is . Part E of the interactive lab fits autoregressions of any series and order.
Worked example: Simple exponential smoothing and Holt's method
The weekly demand for a spare part is 30, 32, 31, 35 and 37 units.
Step 1. Simple exponential smoothing with . Starting from :
| Week | Demand | Level |
|---|---|---|
| 2 | 32 | |
| 3 | 31 | |
| 4 | 35 | |
| 5 | 37 |
The forecast for every following week is 35 units: The method follows the level but not the rise.
Step 2. Holt's method with and . It starts from and the first change . Each week updates the level and then the trend:
Step 3. Forecasts. With and :
The trend term lets the forecast continue the rise. Part F of the lab runs both methods step by step for any series and factors.
Recurrent neural networks
A recurrent network processes a sequence one step at a time and carries a hidden state from step to step, so that it can summarise the past in a fixed-size vector [6]. Training by backpropagation through time suffers from vanishing and exploding gradients, which makes long-range dependencies hard to learn [7]. The long short-term memory cell adds a memory cell whose input and output gates control what is written into it and read from it, and a forget gate, added in later work, controls what is kept; this design lets information and gradients flow across many steps [8]. The gated recurrent unit is a simpler relative [9]. Convolutional networks over time and attention-based transformers are strong alternatives for sequence modelling [10, 11], and surveys compare these families for forecasting [12].
Deep sequence models need data. A monthly series of about eight hundred values is small for an LSTM, and a well-designed regression with seasonal terms is often as accurate. Recurrent networks show their strength with many related series, such as the load of thousands of feeders, and with long high-frequency records, such as the degradation trajectories of turbofan engines in the C-MAPSS simulation data used for remaining useful life prediction [13].
Check your understanding. What problem does the gating of an LSTM address?
Formulas: The recurrent unit, its gradient and the LSTM cell
A recurrent network reads the inputs one at a time and updates a hidden state from the new input and the previous state, with the same weights at every step [6]:
Backpropagation through time applies the chain rule along the sequence. For a single unit with the weight , the derivative of a later state with respect to an earlier one is a product of one factor per step:
If the factors are smaller than 1 in size, the product vanishes exponentially with ; if they are larger, it explodes. Either way, dependencies over many steps are hard to learn [7].
Hochreiter and Schmidhuber introduced a memory cell whose content is changed only by addition, protected by gates [8]. The form used today, for example in PyTorch, has an input gate , a forget gate , an output gate and a candidate , each computed from and with its own weights:
The derivative of the new cell state with respect to the old one along the direct path is the forget gate itself, , so a gate close to 1 carries information and gradients across many steps. An LSTM layer with inputs and hidden units has four sets of weights and, in PyTorch, two bias vectors per set:
Worked example: A recurrent unit and its vanishing gradient
A single unit has , and no bias, starts from and reads the inputs 1, 0.5 and −1:
The gradient. The two factors are
so . Over 20 steps with a typical factor of 0.6, the gradient shrinks to ; with a factor of 1.2 it grows to .
Worked example: One step of an LSTM cell
A cell with one input and one hidden unit has the state and and receives .
Step 1. The gates. Each gate forms its weighted sum with its own weights , and bias , and applies its function:
| Gate | Weighted sum | Value |
|---|---|---|
Step 2. The new states.
Step 3. The path through the cell. Along the cell state, the gradient is multiplied by the forget gate, 0.867611 here. With forget gates of 0.95, it keeps of its size over 20 steps, compared with for the simple unit.
Step 4. Size of the notebook's model. The LSTM of the notebook has input and hidden units, so
and its linear output layer adds , for 4513 parameters, which the 24-month windows of the training period must determine. Part G of the interactive lab runs both cells over a sequence.
Forecasts for decisions
A forecast serves a decision: scheduling generation, sizing a reservoir release, ordering spare parts, or setting emission targets. Point forecasts should therefore come with uncertainty, as prediction intervals or quantiles, and probabilistic forecasting competitions in energy have made this standard practice [5]. The forecast horizon, the update frequency and the cost of errors in each direction belong in the problem statement, as the costs of misses and false alarms did in Week 8.

Formulas: Prediction intervals, quantiles and costs
If the forecast errors are roughly normal with the standard deviation at the horizon , the interval
contains the future value with the chosen probability, where for 95% and for 80%. The spread grows with the horizon; for the naive forecast of a series whose changes are independent with the standard deviation , it is [2]. The share of test values that fall inside the intervals, the coverage, should be close to the nominal level.
A quantile forecast states a value that the observation stays below with the probability . It is scored with the pinball loss, which energy forecasting competitions use [5]:
When an underestimate costs per unit and an overestimate per unit, the expected cost of a decision is . Raising by a small amount saves with the probability and costs with the probability , so the best decision balances both:
The best decision is the quantile of the level of the forecast distribution, not its mean.
Worked example: Intervals for a load forecast
Step 1. One step ahead. A forecast of tomorrow's peak load is 48 MW, and the one-step errors of the past have the standard deviation 2 MW. The 95% interval is
Step 2. Four steps ahead. For a naive forecast four days ahead, MW, and the interval widens to MW.
Step 3. Coverage. If 18 of 20 test days fall inside their 95% intervals, the coverage is . Over many such checks, a coverage persistently below the nominal 95% means that the intervals are too narrow.
Worked example: Pinball loss and the cost of errors
Step 1. Scoring three quantiles. For tomorrow's peak load, the quantile forecasts are , and MW, and the observed peak is 53 MW:
with the mean . The 90% quantile is penalised lightly because the observation lies below it, as it should with the probability 0.9.
Step 2. The best quantile. A utility buys any shortfall on the balancing market for 60 per MWh more than planned energy, and a surplus loses 20 per MWh, illustrative values. The best plan is the quantile of the level
Step 3. The planned load. If the forecast distribution is normal with the mean 50 MW and the standard deviation 4 MW, the 75% quantile is MW, about 2.7 MW above the mean forecast. Part H of the interactive lab computes intervals, pinball losses and cost-optimal quantiles.
Python step 12: Time-indexed data, baselines and exceptions
The Python step of this week is part of the Colab notebook, where every explanation stands next to a cell that runs it and the step closes with a quick check and exercises with immediate feedback. The printable lecture notes contain the same step together with the outputs of its code. The Colab button below opens the notebook at the step. Run the setup cell just above the step first, since the exercises use its check function.
Review cards
Select a card to turn it over.
Continue the week
The week continues with the simulation and the self-assessment of the interactive lab and with the Python step and the hands-on work of the Colab notebook. The week overview lists the discipline challenges, the weekly task and the research assignment.
Interactive lab Colab notebook Self-assessment Week overview and tasks
References
[1] Box, G. E. P., Jenkins, G. M., Reinsel, G. C., & Ljung, G. M. (2015). Time Series Analysis: Forecasting and Control (5th ed.). Wiley.
[2] Hyndman, R. J., & Athanasopoulos, G. (2021). Forecasting: Principles and Practice (3rd ed.). OTexts. https://otexts.com/fpp3/
[3] Keeling, C. D., Bacastow, R. B., Bainbridge, A. E., Ekdahl, C. A., Guenther, P. R., Waterman, L. S., & Chin, J. F. S. (1976). Atmospheric carbon dioxide variations at Mauna Loa Observatory, Hawaii. Tellus, 28(6), 538-551. https://doi.org/10.1111/j.2153-3490.1976.tb00701.x
[4] Lan, X., & Keeling, R. (2026). Trends in atmospheric carbon dioxide: Mauna Loa CO2 monthly mean data. NOAA Global Monitoring Laboratory and Scripps Institution of Oceanography. https://gml.noaa.gov/ccgg/trends/
[5] Hong, T., Pinson, P., Fan, S., Zareipour, H., Troccoli, A., & Hyndman, R. J. (2016). Probabilistic energy forecasting: Global Energy Forecasting Competition 2014 and beyond. International Journal of Forecasting, 32(3), 896-913. https://doi.org/10.1016/j.ijforecast.2016.02.001
[6] Elman, J. L. (1990). Finding structure in time. Cognitive Science, 14(2), 179-211. https://doi.org/10.1207/s15516709cog1402_1
[7] Bengio, Y., Simard, P., & Frasconi, P. (1994). Learning long-term dependencies with gradient descent is difficult. IEEE Transactions on Neural Networks, 5(2), 157-166. https://doi.org/10.1109/72.279181
[8] Hochreiter, S., & Schmidhuber, J. (1997). Long short-term memory. Neural Computation, 9(8), 1735-1780. https://doi.org/10.1162/neco.1997.9.8.1735
[9] Cho, K., van Merriënboer, B., Gulcehre, C., et al. (2014). Learning phrase representations using RNN encoder-decoder for statistical machine translation. In Proceedings of the 2014 Conference on Empirical Methods in Natural Language Processing (EMNLP) (pp. 1724-1734). https://doi.org/10.3115/v1/D14-1179
[10] Bai, S., Kolter, J. Z., & Koltun, V. (2018). An empirical evaluation of generic convolutional and recurrent networks for sequence modeling. arXiv preprint arXiv:1803.01271. https://arxiv.org/abs/1803.01271
[11] Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., Kaiser, Ł., & Polosukhin, I. (2017). Attention is all you need. In Advances in Neural Information Processing Systems 30 (pp. 5998-6008). https://arxiv.org/abs/1706.03762
[12] Lim, B., & Zohren, S. (2021). Time-series forecasting with deep learning: A survey. Philosophical Transactions of the Royal Society A, 379(2194), 20200209. https://doi.org/10.1098/rsta.2020.0209
[13] Saxena, A., Goebel, K., Simon, D., & Eklund, N. (2008). Damage propagation modeling for aircraft engine run-to-failure simulation. In 2008 International Conference on Prognostics and Health Management (pp. 1-9). IEEE. https://doi.org/10.1109/PHM.2008.4711414