The deck opens with a compact definition: predictive analytics is an area of statistics that deals with extracting information from data and using it to predict trends and behavior patterns. And then the mechanism: its core relies on capturing relationships between explanatory variables and the predicted variables from past occurrences, and exploiting them to predict the unknown outcome.
The slides then split the name in two, and the split is the whole justification of the discipline:
| Half of the name | What it commits you to |
|---|---|
| Predictive | The primary objective is the prediction of future events on the basis of data — time series or other — available now. |
| Analytics | Forecasts are used to take decisions now. |
A forecast nobody acts on is a hobby. The management examples given are all decisions with a lead time attached: forecast of goods or services demand; forecast of workforce availability or need; forecast of material requirements and warehouse availabilities; forecast of revenues, profits and losses in order to define future investments.
Different decisions need different distances into the future, and the slides organise them into three bands. The band you are in determines both the model and the tolerance for error.
Resource requirements · workforce shifts · retail sales.
These are the operational decisions of chapter 1: the ones taken again tomorrow. Data is plentiful relative to the horizon, and the series structure (seasonality, day-of-week effects) usually carries most of the signal.
Sales by product category · workforce needs · resource requirements.
The tactical band. Note that resource requirements and workforce appear both here and in the short band: the same quantity is forecast at different granularities for different decisions.
Growth trends · storage needs · sales patterns, market trends.
Here the trend component dominates and the seasonal detail matters less. It is also the band where the occasional component of section 7 — wars, technological breakthroughs, political crises — can invalidate a model outright.
The slides state four properties that a student is expected to repeat without hesitation, starting with the least flattering one.
| Attribute | Consequence |
|---|---|
| Forecasts are usually wrong. | Design the decision so that being wrong is survivable, not so that being right is required. |
| Forecasts are usually not just numbers. | They include mean and dispersion measures, and they include a confidence interval. A bare point forecast has thrown away half of the output. |
| Aggregate forecasts are more reliable than detail ones. | Total sales of a category are easier to predict than the sales of one SKU in one store. |
| Reliability decreases with distance in the future. | The prediction interval widens with the horizon — chapter 4 shows how to estimate it when the library does not give it to you. |
"Forecasts are usually wrong" plus "forecasts include a confidence interval" are one statement, not two. The correct output of a forecasting model is a distribution, summarised by a mean, a dispersion and an interval, and the interval must widen with the horizon.
The deck lays out the space of forecasting methods as a tree with two big branches — objective and subjective — and it is worth keeping the subjective branch in mind, because the rest of the course lives entirely on the objective one.
Very varied. The slides list: sales force composite (aggregation of estimates made by sales agents); polls among customers; opinions of managers; and Delphi — ask the question, gather individual opinions, share the opinions anonymously, re-ask the question, repeat the procedure until consensus. The anonymity is the mechanism: it is what stops the loudest voice from anchoring the room.
Objective models are based on mathematical models, and the slides break the workflow into three high-level phases which recur in every later chapter, under different names.
| Phase | Also called | What it does |
|---|---|---|
| Model specification | identification | The choice of the forecast technique to use. |
| Model fitting | parameter setting | Given the model, sets its parameters to maximise the coherence of forecasts with actual data. |
| Model diagnosis | validation | Determines the level of coherence between actual and forecast data. |
These three phases are exactly the Box-Jenkins methodology you will meet in chapter 4 (identification, parameter estimation, model checking), and exactly the neural modelling process of chapter 5 (architecture choice, training, validation). Recognising the same three-step skeleton under three vocabularies is most of what "knowing the field" means here.
A time series is simply a set of time-indexed values, and it represents the dynamics of a process over time. In the model, we assume to have n observations coming from as many dependent random variables. And the objective of studying them is stated with disarming honesty: to find patterns in past data which can be assumed to repeat in the future. The assumption is doing all the work; when it breaks, so does the forecast.
A time-series plot (timeplot, time series graph) is a bidimensional chart of the series: the vertical axis is the variable of interest, the horizontal axis the time units.
| Organization | Series |
|---|---|
| Sales agent | Daily, weekly, monthly sales |
| Manufacturing company | Monthly labor costs (hours or euros) |
| Manufacturing company | Trimestral sales (units or euros) |
| Local government | Fiscal income (monthly) |
| Local government | Weekly building permits |
| Parish | Attendance at masses, weekly |
| University | Number of students enrolled (absolute, percent) |
| Bank | Loans granted, weekly (number, euro) |
| Agricultural company | Production per hectare, yearly |
| Hospital | Man-days of hospitalization, monthly |
| Family | Telephone costs, bimestrial |
| Series | What it is | File |
|---|---|---|
| THE time series | International airline passengers, monthly totals in thousands, Jan 49 – Dec 60 (G.E.P. Box, G.M. Jenkins, 1976). The canonical trended, multiplicatively seasonal series. | BoxJenkins.csv |
| Jewelry sales | Jewelry market sales, USA, millions of dollars. | gioiellerie.csv |
| Fil rouge | Daily TV sales, 20 quarters from 2004 to 2008. Twenty points is deliberately too few, which is why every method can be traced by hand on it. | FilRouge.csv |
df = pd.read_csv("BoxJenkins.csv")
plt.plot(df.Passengers, label="passengers")
plt.legend()
df = pd.read_csv("FilRouge.csv")
plt.plot(df.sales, label="TV sales")
plt.grid(); plt.legend(); plt.show()
The fil rouge itself, quarter by quarter, is worth having in front of you for the rest of the chapter:
| t | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|---|---|---|---|
| sales | 128 | 181 | 87 | 219 | 407 | 226 | 214 | 383 | 505 | 387 |
| t | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| sales | 278 | 523 | 572 | 354 | 404 | 673 | 752 | 468 | 419 | 725 |
The slides point at Tyler Vigen's spurious correlations when introducing the timeplot. Two series can track each other beautifully for a decade with no causal relation whatsoever. Correlation between series is a hypothesis generator, never evidence.
Forecasting a time series means predicting the values it is going to take in the future. The slides distinguish three settings, and the third is the one most real problems fall into.
| Setting | Inputs | Where it appears later |
|---|---|---|
| Univariate | Only the previous values of the series itself. | AR, MA, ARIMA, SES, HW (ch. 4) |
| Multivariate | Predicts the values of multiple time series. | VAR, VARMA, VARMAX (ch. 4) |
| In-between | Uses predictors other than the single series (exogenous variables) to forecast one series. | SARIMAX (ch. 4), tree and neural models with features (ch. 5-6) |
The slides put the two families side by side without pretending the choice is obvious.
Based on a well-defined theoretical corpus, and it yields justified results. After training on historical data, an equation presents the relationship between the load and its corresponding factors. Regression models, Box-Jenkins models, exponential smoothing and Kalman filters all belong here.
More recent, often provides better results but without justification of the applied models. The slides note, with a visible eyebrow raised — three question marks in the original — that AI methods are said to copy "the human way of thinking". Expert systems, evolutionary programming and fuzzy systems were tried; by far the most effective are machine learning methods, neural or otherwise.
Statistical methods have difficulties in identifying complex nonlinear relationships among factors, but are explainable in their results. That single sentence is the reason the exam project demands one method from each family: you are expected to be able to feel the difference on your own data, not to be told about it.
Regression analysis tries to estimate the relationships among variables, usually between a dependent variable and one or more independent variables (or predictors). It estimates a function. It is not limited to prediction and forecasting: more generally, it wants to determine the value of the dependent variable when the independent variables are fixed.
Then comes a vocabulary distinction the slides are emphatic about, because ML literature blurs it. Regression is the general term often used in the machine learning literature to refer to prediction tasks. But:
| Term | Definition | Error is called |
|---|---|---|
| Prediction | In-sample observations: a model of the data. Predicted values are calculated for observations in the sample used to estimate the regression. | Residual — the difference between the actual value of Y and its predicted value for observations in the sample. |
| Forecast | Out-of-sample observations: made for some date beyond the data used to estimate the regression; the data of the forecasted variable is not in the estimation sample. | Forecast error — the difference between the future value of Y, not contained in the estimation sample, and the forecast of that future value. |
Residual ≠ forecast error. A residual is measured on data the model has already seen; a forecast error on data it has not. A model can drive residuals to zero and still forecast disastrously — which is precisely the definition of overfitting in section 11. When someone quotes an "error" for a model, the first question is always: in-sample or out-of-sample?
Time series decomposition deconstructs a time series into several components, each representing one of the underlying categories of patterns. The common decomposition is into trend, seasonal, cyclical and random components — plus, in the slides, an occasional component that deserves its own discussion.
| Component | Definition from the slides |
|---|---|
| Trend | Typically a persistent increasing or decreasing direction in the data. Usually modelled by a linear, quadratic or exponential function. |
| Seasonal | Repetitive patterns, typically over periods of weeks, months or years. Has a fixed period L. |
| Cyclical | Repeated but non-periodic fluctuations (non-seasonal) lasting at least two years, typically due to changes in economic conditions (recessions, expansions). |
| Random (irregular, noise) | Random, irregular influences. |
| Occasional | Rare: war events, important technological innovations, political crises. Needs a model change. |
The camper sales example from the slides shows all three of the structured components at once: a seasonality where Q3 > Q2 > Q1 > Q4 of the previous year, a long-term trend, and economic cycles visible as the recessions of the 1980s and 1990s. The GDP of Italy from 1861 to 2017, and a power-energy forecast, are shown as cases where an occasional component forces a model change: no amount of parameter fitting rescues a model across a structural break.
The hypothesis behind decomposition is that the observed values result from the combination of different components. How they combine is a modelling choice with a clear rule of thumb:
| Model | Form | Use it when |
|---|---|---|
| Additive | y = T + s + c + e | the variations around the trend do not vary with the level of the time series |
| Multiplicative | y = T × s × c × e | the trend is proportional to the level of the time series |
| Mixed | y = T × s × c + e | seasonal amplitude scales with level, but the noise does not |
A common model is STL — seasonal decomposition of time series by Loess, where Loess is short for local regression. It decomposes the series into seasonal, trend and irregular, with the cyclical component included in the trend plot.
from statsmodels.tsa.seasonal import seasonal_decompose
plt.rcParams['figure.figsize'] = (10.0, 6.0)
df = pd.read_csv('BoxJenkins.csv', usecols=["Passengers"])
ds = df[df.columns[0]] # converts to series
result = seasonal_decompose(ds, model='multiplicative', period=12)
result.plot()
plt.show()
Real series often have more than one period at once — a daily and a weekly rhythm, say. The slides list three packages that can identify multiple seasonalities: MSTL (in statsmodels), Facebook's Prophet, and BATS / TBATS.
Rather than call a library and admire the plot, the deck rebuilds STL by hand on the fil rouge, and projects it into the future. Three ingredients are defined first.
| Tool | Definition from the slides |
|---|---|
| Linear regression | Computes a linear function that minimises the global distance from the dataset points. |
| Moving average | Creates a series of averages of different subsets of the full data set. Subsets are modified by shifting forward: excluding the first number of the series and including the next value. |
| Centered moving average (CMA) | Aligns each moving average with the middle of the time span of the observations it averages. If computed on an even number of terms, you need to average the averaged values. |
We look for the interpolation line y = a·x + b minimising the mean square error over all data pairs (xi, yi). Analytically, with mean values x̄ and ȳ:
a = Σ(xᵢ - x̄)(yᵢ - ȳ) / Σ(xᵢ - x̄)²
b = ȳ - a · x̄
which in the vectorised form the slides use for Python becomes:
On the twenty fil rouge points the arithmetic gives x̄ = 10.5, ȳ = 395.25, and
| quantity | value |
|---|---|
| slope a | 25.88796992 |
| intercept b | 123.4263158 |
| trend at t = 1 | 149.3142857 |
| trend at t = 20 | 641.1857143 |
Sanity check on the first row: 25.888 × 1 + 123.426 = 149.314, against an observed 128. The gap is what the seasonal coefficient will absorb.
Seasonality induces periodic fluctuations around the trend, and to model it we need a coefficient to multiply the trend by. But first we must find the periodicity (wavelength) — the number of seasons. The slides pick autocorrelograms, noting that the correlation of two time series can be quantified by Pearson's index (parametric) or Spearman's (nonparametric).
A correlogram, or autocorrelation plot, is a chart that represents the autocorrelation of a time series as a function of the lag used for computing the autocorrelation. Concretely: build a table where beside the column yt you place the columns yt-1, yt-2, …, yt-K, start from the (K+1)-th row so that all the compared series have equal length, and compute for each k the correlation
rₖ = Σₕ(yₜ - ȳ)(yₜ₋ₖ - ȳ) / Σₕ(yₜ - ȳ)²
Pairs (k, rₖ) are then plotted with lags on the x-axis and the corresponding correlation on the y-axis.
Computed on the raw fil rouge with Pearson, the slides report:
| lag k | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|---|
| rₖ | 1.000 | 0.126 | -0.380 | 0.370 | 0.907 | 0.139 | -0.271 | 0.560 | 0.842 |
The reading is immediate and is the one the slides write on the chart: peaks at lag 4 and lag 8, therefore seasonality of 4. Quarterly data, four seasons, as the calendar column of the original table promised.
Correlograms can be widely different, but the slides single out three cases you should be able to recognise on sight: the correlogram of the original data series; the correlogram of the residuals after detrending; and the correlogram of the residuals after detrending and deseasoning. A slowly decaying correlogram means a trend is still present; a comb of peaks at multiples of L means seasonality is still present; a flat correlogram near zero means there is nothing structured left to model — which is the goal.
import numpy as np, pandas as pd, matplotlib.pyplot as plt
from statsmodels.graphics.tsaplots import plot_acf, plot_pacf
df = pd.read_csv('FilRouge.csv', usecols=[1], names=['value'], header=0)
plt.rcParams.update({'figure.figsize':(9,7), 'figure.dpi':120})
fig, axes = plt.subplots(2, 2, sharex=True)
axes[0, 0].plot(df.value); axes[0, 0].set_title('Original Series')
plot_acf(df.value, ax=axes[0, 1])
# 1st Differencing
axes[1, 0].plot(df.value.diff()); axes[1, 0].set_title('1st Order Differencing')
plot_acf(df.value.diff().dropna(), ax=axes[1, 1])
plt.show()
With the period known, the seasonal coefficient is built in three moves.
SUMPRODUCT over rows matching the modulus, divided by the number of complete seasons.VLOOKUP on the modulus) and multiply the trend by it.The four coefficients that come out of the fil rouge are:
| quarter position (t mod 4) | 1 | 2 | 3 | 0 |
|---|---|---|---|---|
| coefficient s | 1.292340 | 0.875749 | 0.657316 | 1.142187 |
| reading | peak quarter, +29% | -12% | trough, -34% | +14% |
Multiplying trend by coefficient reconstructs the seasonal model: at t = 1, 149.314 × 1.29234 = 192.96; at t = 5, 252.866 × 1.29234 = 326.79; at t = 20, 641.186 × 1.142187 = 732.35.
To eliminate the effect of st we divide by st; what is left is trend plus random component. The slides tabulate it:
| t | yt | st | deseasoned |
|---|---|---|---|
| 1 | 128 | 1.29 | 99.05 |
| 2 | 181 | 0.88 | 206.68 |
| 3 | 87 | 0.66 | 132.36 |
| 4 | 219 | 1.14 | 191.74 |
| … | … | … | … |
| 19 | 419 | 0.66 | 637.44 |
| 20 | 725 | 1.14 | 634.75 |
Having the coefficients of the trend and of the seasonal components, we can project the model onto future periods. Extend the trend line past t = 20 and multiply by the coefficient of the corresponding season:
| t | trend | st | forecast |
|---|---|---|---|
| 21 | 667.074 | 1.29 | 862.09 |
| 22 | 692.962 | 0.88 | 606.86 |
| 23 | 718.850 | 0.66 | 472.51 |
| 24 | 744.738 | 1.14 | 850.63 |
The trend and the four seasonal coefficients are exactly the ones computed in the slides. Toggle the layers, and push the horizon to see the projection of section 10.
Under the forecast chart the deck writes: variance grows too much. A log transform preprocessing was in order. The multiplicative seasonal model amplifies the swing as the trend rises, and by t = 24 the peaks and troughs are implausibly far apart. This is the hand-off to chapter 3: the fix is not a better model, it is a transform applied before modelling.
The slides are categorical: in any learning process, performance should be estimated with out-of-sample validation, withholding some of the sample data from model identification (the training phase), then using the model to make forecasts for the hold-out data (the test data). The testing dataset should never be used in the learning step.
Two definitions follow, and they close the loop with section 6: predictions on train values are called fitted values, and the corresponding errors are called residuals.
k-fold cross validation repeats the split by dividing the data into k groups, each given a chance to be held out — but it cannot be used when learning on data series. The reason is temporal: a fold taken from the middle of a series would train the model on the future to predict the past. Series validation must respect the arrow of time, which in practice means a split point, or a rolling origin.
Errors on train data can be much smaller than those on test data, in case of overfitting. The slides name two circumstances in which it is likely:
The second is subtler and more common: if you grid-search a hundred configurations and keep the one with the lowest in-sample error, the winning score is a selection artefact, not a performance estimate. Chapter 9 returns to this when it discusses grid search and Optuna.
The mechanics are mundane: select an arbitrary split point in the ordered list of observations and create two datasets. Depending on how much data you have and how much the model needs, splits of 50-50, 70-30 or 90-10 are used.
ds = pd.read_csv('BoxJenkins.csv', header=0)
X = ds.Passengers.values
train_size = int(len(X) * 0.66)
train, test = X[0:train_size], X[train_size:len(X)]
print('Observations: %d' % (len(X)))
print('Training Observations: %d' % (len(train)))
print('Testing Observations: %d' % (len(test)))
plt.plot(train)
plt.plot([None for i in train] + [x for x in test])
plt.show()
Move the split point and watch how much history is left to fit a trend and four seasonal coefficients. With twenty quarterly points, an aggressive test share leaves fewer than two full seasons to learn from.
The slides append a self-criticism to the fil rouge worked example: we should have reserved the last data for testing! The empirical STL of sections 8 to 10 was fitted on all twenty points and then projected — so its "forecast" was never validated. Reproducing that mistake in the exam project is the fastest way to lose marks on methodology.
Predictive: the primary objective is the prediction of future events on the basis of data — time series or other — available now. Analytics: forecasts are used to take decisions now. The core of the discipline is capturing relationships between explanatory variables and predicted variables from past occurrences and exploiting them to predict the unknown outcome.
(1) Forecasts are usually wrong. (2) They are usually not just numbers: they include mean and dispersion measures and a confidence interval. (3) Aggregate data forecasts are more reliable than detail data ones. (4) Reliability decreases with the distance in the future.
A subjective forecasting method: ask the question, gather individual opinions, share the opinions anonymously, re-ask the question, and repeat the procedure until consensus. The anonymity is the operative feature — it lets participants revise towards the group without deferring to status. Other subjective methods listed are the sales force composite, polls among customers and opinions of managers.
Model specification (identification) — choosing the forecast technique to use. Model fitting (parameter setting) — given the model, setting its parameters to maximise coherence of forecasts with actual data. Model diagnosis (validation) — determining the level of coherence between actual and forecast data.
Prediction is in-sample: values computed for observations in the sample used to estimate the regression; its error is the residual, the difference between the actual Y and its predicted value inside the sample. Forecast is out-of-sample: made for a date beyond the estimation data; its error is the forecast error, the difference between the future value of Y — not in the estimation sample — and the forecast of it. In ML literature "regression" is often used loosely for both.
Trend (persistent increasing or decreasing direction, modelled by a linear, quadratic or exponential function); seasonal (repetitive patterns over weeks, months or years, with a fixed period L); cyclical (repeated but non-periodic fluctuations, non-seasonal, lasting at least two years, typically caused by economic conditions such as recessions and expansions); random/irregular noise; and the occasional component — rare events such as wars, major technological innovations or political crises, which require a model change.
An additive model (y = T + s + c + e) is used when the variations around the trend do not vary with the level of the series. A multiplicative model (y = T × s × c × e) is used when the trend is proportional to the level of the series. A mixed model (y = T × s × c + e) combines the two.
STL is seasonal decomposition of time series by Loess (local regression). It decomposes the series into seasonal, trend and irregular. The cyclical component is included in the trend component plot. For series with more than one period, the slides point to MSTL, Facebook's Prophet, and BATS/TBATS.
Beside the column yt you place K lagged columns yt-1 … yt-K, start from the (K+1)-th row so all columns have equal length, and compute the correlation (Pearson, or Spearman for the nonparametric version) between yt and each lagged column. Plot (k, rk). On the fil rouge the coefficients were 1.000, 0.126, -0.380, 0.370, 0.907, 0.139, -0.271, 0.560, 0.842 for lags 0 to 8: the peaks at lag 4 and lag 8 identify a seasonality of 4.
The least-squares trend on twenty points is y = 25.888·t + 123.426, so at t = 21 the trend value is 667.074. The season index of t = 21 is the same as t = 1, whose coefficient — the average relative elongation y/T over that season position — is 1.29234. The forecast is the product: 667.074 × 1.29234 ≈ 862.09.
The comment is that the variance grows too much: with a multiplicative seasonal model on a rising linear trend, the peak-to-trough swing widens without bound. A log transform as preprocessing was in order — the topic of chapter 3, where the log transform is presented precisely as the way to make a series stationary in variance.
k-fold repeatedly splits the data into k groups, each in turn held out. On a data series this breaks the temporal order: a middle fold would have the model trained on future values to predict past ones, leaking information. Instead one chooses a split point in the ordered observations — 50-50, 70-30 or 90-10 — and never lets the test data touch the learning step.
(1) When a model with a large number of parameters has been fitted to a too small sample. (2) When the model has been selected from a large set of candidate models precisely by minimising RMSE in the estimation period — the reported score is then a product of the selection, not an estimate of future performance.