83
Computational Intelligence Methods for Time Series Prediction Second European Business Intelligence Summer School (eBISS 2012) Gianluca Bontempi Département d’Informatique Boulevard de Triomphe - CP 212 http://www.ulb.ac.be/di Computational Intelligence Methods for Prediction – p. 1/83

Computational Intelligence for Time Series Prediction

Embed Size (px)

Citation preview

Page 1: Computational Intelligence for Time Series Prediction

Computational Intelligence Methodsfor Time Series Prediction

Second European Business Intelligence SummerSchool (eBISS 2012)

Gianluca Bontempi

Département d’Informatique

Boulevard de Triomphe - CP 212

http://www.ulb.ac.be/di

Computational Intelligence Methods for Prediction – p. 1/83

Page 2: Computational Intelligence for Time Series Prediction

Outline• Introduction (5 mins )

• Notions of time series (30 mins )

• Machine learning for prediction (60 mins )• bias/variance• parametric and structural identification• validation• model selection

• feature selection

• Local learning

• Forecasting: one-step and multi-step-ahed (30 mins )

• Some applications (30 mins )• time series competitions• chaotic time series• wireless sensor

• biomedical

• Future directions and perspectives (15 mins )

Computational Intelligence Methods for Prediction – p. 2/83

Page 3: Computational Intelligence for Time Series Prediction

ULB Machine Learning Group (MLG)• 8 researchers (2 prof, 5 PhD students, 4 postdocs).

• Research topics: Knowledge discovery from data, Classification, Computationalstatistics, Data mining, Regression, Time series prediction, Sensor networks,

Bioinformatics, Network inference.

• Computing facilities: high-performing cluster for analysis of massive datasets,Wireless Sensor Lab.

• Website: mlg.ulb.ac.be.

• Scientific collaborations in ULB: Bioinformatique des génomes et des réseaux

(IBMM), CENOLI (Sciences), Microarray Unit (Hopital Jules Bordet), Laboratoirede Médecine experimentale, Laboratoire d’Anatomie, Biomécanique et

Organogénèse (LABO), Service d’Anesthesie (ERASME).

• Scientific collaborations outside ULB: Harvard Dana Farber (US), UCL Machine

Learning Group (B), Politecnico di Milano (I), Universitá del Sannio (I), HelsinkiInstitute of Technology (FIN).

Computational Intelligence Methods for Prediction – p. 3/83

Page 4: Computational Intelligence for Time Series Prediction

ULB-MLG: recent projects1. Adaptive real-time machine learning for credit card fraud detection

2. Discovery of the molecular pathways regulating pancreatic beta cell dysfunctionand apoptosis in diabetes using functional genomics and bioinformatics: ARC

(2010-2015)

3. ICT4REHAB - Advanced ICT Platform for Rehabilitation (2011-2013)

4. Integrating experimental and theoretical approaches to decipher the molecular

networks of nitrogen utilisation in yeast: ARC (2006-2010).

5. TANIA - Système d’aide à la conduite de l’anesthésie. WALEO II project funded

by the Région Wallonne (2006-2010)

6. "COMP2SYS" (COMPutational intelligence methods for COMPlex SYStems)

MARIE CURIE Early Stage Research Training funded by the EU (2004-2008).

Computational Intelligence Methods for Prediction – p. 4/83

Page 5: Computational Intelligence for Time Series Prediction

Time seriesDefinition A time series is a sequence of observations, usually ordered intime.

Examples of time series

• Weather variables, like temperature, pressure

• Economic factors.

• Traffic.

• Activity of business.

• Electric load, power consumption.

• Financial index.

• Voltage.

Computational Intelligence Methods for Prediction – p. 5/83

Page 6: Computational Intelligence for Time Series Prediction

Why studying time series?There are various reasons:

Prediction of the future based on the past.

Control of the process producing the series.

Understanding of the mechanism generating the series.

Description of the salient features of the series.

Computational Intelligence Methods for Prediction – p. 6/83

Page 7: Computational Intelligence for Time Series Prediction

Univariate discrete time series• Quantities, like temperature and voltage, change in a continuous way.

• In practice, however, the digital recording is made discretely in time.

• We shall confine ourselves to discrete time series (which however takecontinuous values).

• Moreover we will consider univariate time series, where one type ofmeasurement is made repeatedly on the same object or individual.

Computational Intelligence Methods for Prediction – p. 7/83

Page 8: Computational Intelligence for Time Series Prediction

A general modelLet an observed discrete univariate time series be y1, . . . , yT . This meansthat we have T numbers which are observations on some variable made at T

equally distant time points, which for convenience we label 1, 2, . . . , T .

A fairly general model for the time series can be written

yt = g(t) + ϕt t = 1, . . . , T

The observed series is made of two components

Systematic part: g(t), also called signal or trend, which is a determisticfunction of time

Stochastic sequence: a residual term ϕt, also called noise, which follows aprobability law.

Computational Intelligence Methods for Prediction – p. 8/83

Page 9: Computational Intelligence for Time Series Prediction

Types of variationTraditional methods of time-series analysis are mainly concerned withdecomposing the variation of a series yt into:

Trend : this is a long-term change in the mean level, eg. an increasing trend.

Seasonal effect : many time series (sale figures, temperature readings) exhibitvariation which is seasonal (e.g. annual) in period. The measure and theremoval of such variation brings to deseasonalized data.

Irregular fluctuations : after trend and cyclic variations have been removedfrom a set of data, we are left with a series of residuals, which may ormay not be completely random.

We will assume here that once we have detrended and deseasonalized theseries, we can still extract information about the dependency between thepast and the future. Henceforth ϕt will denote the detrended anddeseasonalized series.

Computational Intelligence Methods for Prediction – p. 9/83

Page 10: Computational Intelligence for Time Series Prediction

320

340

360

obse

rved

320

340

360

tren

d−

3−

11

23

seas

onal

−0.

50.

00.

5

1960 1970 1980 1990

rand

om

Time

Decomposition of additive time series

Decomposition returned by the R package forecast.

Computational Intelligence Methods for Prediction – p. 10/83

Page 11: Computational Intelligence for Time Series Prediction

Probability and dependency• Forecasting a time series is possible since future depends on the past or

analogously because there is a relationship between the future and thepast. However this relation is not deterministic and can hardly be writtenin an analytical form.

• An effective way to describe a nondeterministic relation between twovariables is provided by the probability formalism.

• Consider two continuous random variables ϕ1 and ϕ2 representing forinstance the temperature today and tomorrow. We tend to believe thatϕ1 could be used as a predictor of ϕ2 with some degree of uncertainty.

• The stochastic dependency between ϕ1 and ϕ2 is resumed by the jointdensity p(ϕ1, ϕ2) or equivalently by the conditional probability

p(ϕ2|ϕ1) =p(ϕ1, ϕ2)

p(ϕ1)

• If p(ϕ2|ϕ1) 6= p(ϕ2) then ϕ1 and ϕ2 are not independent or equivalentlythe knowledge of the value of ϕ1 reduces the uncertainty about ϕ2.

Computational Intelligence Methods for Prediction – p. 11/83

Page 12: Computational Intelligence for Time Series Prediction

Stochastic processes• A discrete-time stochastic process is a collection of random variables ϕt,

t = 1, . . . , T defined by a joint density

p(ϕ1, . . . , ϕT )

• Statistical time-series analysis is concerned with evaluating theproperties of the probability model which generated the observed timeseries.

• Statistical time-series modeling is concerned with inferring theproperties of the probability model which generated the observed timeseries from a limited set of observations.

Computational Intelligence Methods for Prediction – p. 12/83

Page 13: Computational Intelligence for Time Series Prediction

Strictly stationary processes• Definition A stochastic process is said to be strictly stationary if the joint

distribution of ϕt1, ϕt2

, . . . , ϕtnis the same as the joint distribution of

ϕt1+k, ϕt2+k, . . . , ϕtn+k for all n, t1, . . . , tn and k.

• In other words shifting the time origin by an amount k has no effect onthe joint distribution which depends only on the intervals betweent1, . . . , tn.

• This implies that the distribution of ϕt is the same for all t.

• The definition holds for any value of n.

• Let us see what does it mean in practice for n = 1 and n = 2.

Computational Intelligence Methods for Prediction – p. 13/83

Page 14: Computational Intelligence for Time Series Prediction

Propertiesn=1 : If ϕt is strictly stationary and its first two moments are finite, we have

µt = µ σ2t = σ2

n=2 : Furthermore the autocovariance function γ(t1, t2) depends only on thelag k = t2 − t1 and may be written by

γ(k) = Cov[ϕt, ϕt+k]

In order to avoid scaling effects, it is useful to introduce theautocorrelation function

ρ(k) =γ(k)

σ2=

γ(k)

γ(0)

Computational Intelligence Methods for Prediction – p. 14/83

Page 15: Computational Intelligence for Time Series Prediction

Weak stationarity• A less restricted definition of stationarity concerns only the first two

moments of ϕt

Definition A process is called second-order stationary or weakly stationary

if its mean is constant and its autocovariance function depends only onthe lag.

• No assumptions are made about higher moments than those of secondorder.

• Strict stationarity implies weak stationarity.

• In the special case of normal processes, weak stationarity implies strictstationarity.

Definition A process is called normal is the joint distribution ofϕt1

, ϕt2, . . . , ϕtn

is multivariate normal for all t1, . . . , tn.

Computational Intelligence Methods for Prediction – p. 15/83

Page 16: Computational Intelligence for Time Series Prediction

Purely random processes• It consists of a sequence of random variables ϕt which are mutually

independent and identically distributed. For each t and k

p(ϕt+k|ϕt) = p(ϕt+k)

• It follows that this process has constant mean and variance. Also

γ(k) = Cov[ϕt, ϕt+k] = 0

for k = ±1,±2, . . . .

• A purely random process is strictly stationary.

• A purely random process is sometimes called white noise particularly byengineers.

Computational Intelligence Methods for Prediction – p. 16/83

Page 17: Computational Intelligence for Time Series Prediction

Example: Gaussian purely random

0 10 20 30 40 50 60 70 80 90 100−2.5

−2

−1.5

−1

−0.5

0

0.5

1

1.5

2

2.5Gaussian purely random

Computational Intelligence Methods for Prediction – p. 17/83

Page 18: Computational Intelligence for Time Series Prediction

Example: Uniform purely random

0 10 20 30 40 50 60 70 80 90 1000

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1Uniform purely random

Computational Intelligence Methods for Prediction – p. 18/83

Page 19: Computational Intelligence for Time Series Prediction

Random walk• Suppose that wt is a discrete, purely random process with mean µ and

variance σ2w

.

• A process ϕt is said to be a random walk if

ϕt = ϕt−1 + wt

• If ϕ0 = 0 then

ϕt =t

i=1

wi

• E[ϕt] = tµ and Var [ϕt] = tσ2w

.

• As the mean and variance change with t the process is non-stationary.

Computational Intelligence Methods for Prediction – p. 19/83

Page 20: Computational Intelligence for Time Series Prediction

Random walk (II)• The first differences of a random walk given by

∇ϕt = ϕt − ϕt−1

form a purely random process, which is stationary.

• The best-known examples of time series which behave like randomwalks are share prices on successive days.

Computational Intelligence Methods for Prediction – p. 20/83

Page 21: Computational Intelligence for Time Series Prediction

Ten random walksLet w ∼ N (0, 1).

0 50 100 150 200 250 300 350 400 450 500−40

−30

−20

−10

0

10

20

30

40

50

60Random walks

Computational Intelligence Methods for Prediction – p. 21/83

Page 22: Computational Intelligence for Time Series Prediction

Autoregressive processesSuppose that wt is a purely random process with mean zero and varianceσ2w

. A process ϕt is said to be an autoregressive process of order p (also anAR(p) process) if

ϕt = α1ϕt−1 + · · · + αpϕt−p + wt

Note that this is like a multiple regression model where ϕ is regressed not onindependent variables but on its past values (hence the prefix “auto”).

Computational Intelligence Methods for Prediction – p. 22/83

Page 23: Computational Intelligence for Time Series Prediction

First order AR(1) processIf p = 1, we have the so-called Markov process AR(1)

ϕt = αϕt−1 + wt

By substitution it can be shown that

ϕt = α(αϕt−2 + wt−1) + wt = α2(αϕt−3 + wt−2) + αwt−1 + wt =

= wt + αwt−1 + α2wt−2 + . . .

ThenE[ϕt] = 0 Var [zt] = σ2

w(1 + α2 + α4 + . . . )

Then if |α| < 1 the variance if finite and equals

Var [ϕt] = σ2ϕ

= σ2w

/(1 − α2)

and the autocorrelation is

ρ(k) = αk k = 0, . . . , 1, 2

Computational Intelligence Methods for Prediction – p. 23/83

Page 24: Computational Intelligence for Time Series Prediction

General order AR(p) processWe can find again the duality between AR and infinite-order MA. By using theB operator, the AR(p) process is

(1 − α1B − · · · − αpBp)ϕt = zt

or equivalently

ϕt = zt/(1 − α1B − · · · − αpBp) = f(B)zt

where

f(B) = (1 − α1B − · · · − αpBp)−1 = (1 + β1B + β2B

2 + . . . )

It has been shown that condition necessary and sufficient for the stationarityis that the roots of the equation

φ(B) = 1 − α1B − · · · − αpBp = 0

lie outside the unit circle.

Computational Intelligence Methods for Prediction – p. 24/83

Page 25: Computational Intelligence for Time Series Prediction

Autocorrelation in AR(q)Unlike the autocorrelation function in MA(q) which cuts off at lag q, theautocorrelation of an AR(q) attenuates slowly.

0 10 20 30 40 50 60 70 800

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8AR(16) correlation (absolute value)

Computational Intelligence Methods for Prediction – p. 25/83

Page 26: Computational Intelligence for Time Series Prediction

Fitting an autoregressive processThe estimation of an autoregressive process to a set of dataDT = {ϕ1, . . . , ϕT } demands the resolution of two problems:

1. The estimation of the order p of the process.

2. The estimation of the set of parameters {α1, . . . , αp}.

Computational Intelligence Methods for Prediction – p. 26/83

Page 27: Computational Intelligence for Time Series Prediction

Estimation of AR(p) parametersSuppose we have an AR(p) process of order p

ϕt = α1ϕt−1 + · · · + αpϕt−p + wt

Given T observations, the parameters may be estimated by least-squares byminimizing

α = arg minα

T∑

t=p+1

[ϕt − α1ϕt−1 + · · · + αpϕt−p]2

In matrix form this amounts to solve the multiple least-squares problem where

Computational Intelligence Methods for Prediction – p. 27/83

Page 28: Computational Intelligence for Time Series Prediction

Estimation of AR(p) parameters (II)

X =

ϕT−1 ϕT−2 . . . ϕT−p−1

ϕT−2 ϕT−3 . . . ϕT−p−2

......

......

ϕp ϕp−1 . . . ϕ1

Y =

ϕT

ϕT−1

...

ϕp+1

(1)

Most of the considerations made for multiple linear regression still hold in thiscase.

Computational Intelligence Methods for Prediction – p. 28/83

Page 29: Computational Intelligence for Time Series Prediction

The NAR representation• AR models assume that the relation between past and future is linear

• Once we assume that the linear assumption does not hold, we mayextend the AR formulation to a Nonlinear Auto Regressive (NAR)formulation

ϕt = f(

ϕt−d, ϕt−d−1, . . . , ϕt−d−n+1)

+ w(t)

where the missing information is lumped into a noise term w.

• In what follows we will consider this relationship as a particular instanceof a dependence

y = f(x) + w

between a multidimensional input x ∈ X ⊂ Rn and a scalar output y ∈ R.

Computational Intelligence Methods for Prediction – p. 29/83

Page 30: Computational Intelligence for Time Series Prediction

Nonlinear vs. linear• AR models assume that the relation between past and future is linear

• The advantage of linear models are numerous:• the least-squares β estimate can be expressed in an analytical form• the least-squares β estimate can be easily calculated through matrix

computation.• statistical properties of the estimator can be easily defined.• recursive formulation for sequential updating are avaialble.• the relation between empirical and generalization error is known.

• Unfortunately in real problem it is extremely unlikely that the input andouput variables are linked by a linear relation.

• Moreover, the form of the relation is often unknown and only a limitedamount of samples is available.

Computational Intelligence Methods for Prediction – p. 30/83

Page 31: Computational Intelligence for Time Series Prediction

Supervised learning

TRAINING DATASET

UNKNOWN

DEPENDENCY

INPUT OUTPUTERROR

PREDICTION

MODELPREDICTION

The prediction problem is also known as the supervised learning problem,because of the presence of the outcome variable which guides the learningprocess.Collecting a set of training data is analogous to the situation where a teachersuggests the correct answer for each input configuration.

Computational Intelligence Methods for Prediction – p. 31/83

Page 32: Computational Intelligence for Time Series Prediction

The regression plus noise form• A typical way of representing the unknown input/output relation is the

regression plus noise form

y = f(x) + w

where f(·) is a deterministic function and the term w represents thenoise or random error. It is typically assumed that w is independent of x

and E[w] = 0.

• Suppose that we have available a training set {〈xi, yi〉 : i = 1, . . . , N},where xi = (xi1, . . . , xin), generated according to the previous model.

• The goal of a learning procedure is to find a model h(x) which is able togive a good approximation of the unknown function f(x).

• But how to choose h,if we do not know the probability distributionunderlying the data and we have only a limited training set?

Computational Intelligence Methods for Prediction – p. 32/83

Page 33: Computational Intelligence for Time Series Prediction

A simple example

−2 −1 0 1 2

−5

05

1015

x

Y

Computational Intelligence Methods for Prediction – p. 33/83

Page 34: Computational Intelligence for Time Series Prediction

Model 1

−2 −1 0 1 2

−5

05

1015

x

Y

Training error= 2 degree= 1

Computational Intelligence Methods for Prediction – p. 34/83

Page 35: Computational Intelligence for Time Series Prediction

Model 2

−2 −1 0 1 2

−5

05

1015

x

Y

Training error= 0.92 degree= 3

Computational Intelligence Methods for Prediction – p. 35/83

Page 36: Computational Intelligence for Time Series Prediction

Model 3

−2 −1 0 1 2

−5

05

1015

x

Y

Training error= 0.4 degree= 18

Computational Intelligence Methods for Prediction – p. 36/83

Page 37: Computational Intelligence for Time Series Prediction

Generalization and overfitting• How to estimate the quality of a model? Is the training error a good

measure of the quality?

• The goal of learning is to find a model which is able to generalize , i.e. ableto return good predictions for input sets independent of the training set.

• In a nonlinear setting, it is possible to find models with such a complicatestructure that they have a null empirical risk. Are these models good?

• Typically NOT. Since doing very well on the training set could meandoing badly on new data.

• This is the phenomenon of overfitting .

• Using the same data for training a model and assessing it is typically awrong procedure, since this returns an over optimistic assessment of themodel generalization capability.

Computational Intelligence Methods for Prediction – p. 37/83

Page 38: Computational Intelligence for Time Series Prediction

Bias and variance of a modelA result of estimation theory shows that the mean-squared-error, i.e. ameasure of the generalization quality of an estimator can be decomposedinto three terms:

MSE = σ2w

+ squared bias + variance

where the intrinsic noise term reflects the target alone, the bias reflects thetarget’s relation with the learning algorithm and the variance term reflects thelearning algorithm alone.This result is theoretical since these quantities cannot be measured on thebasis of a finite amount of data. However, this result provide insight aboutwhat makes accurate a learning process.

Computational Intelligence Methods for Prediction – p. 38/83

Page 39: Computational Intelligence for Time Series Prediction

The bias/variance trade-off• The first term is the variance of y around its true mean f(x) and cannot

be avoided no matter how well we estimate f(x), unless σ2w

= 0.

• The bias measures the difference in x between the average of theoutputs of the hypothesis functions over the set of possible DN and theregression function value f(x)

• The variance reflects the variability of the guessed h(x, αN ) as onevaries over training sets of fixed dimension N . This quantity measureshow sensitive the algorithm is to changes in the data set, regardless tothe target.

Computational Intelligence Methods for Prediction – p. 39/83

Page 40: Computational Intelligence for Time Series Prediction

The bias/variance dilemma• The designer of a learning machine has not access to the term MSE but

can only estimate it on the basis of the training set. Hence, thebias/variance decomposition is relevant in practical learning since itprovides a useful hint about the features to control in order to make theerror MSE small.

• The bias term measures the lack of representational power of the classof hypotheses. To reduce the bias term we should consider complexhypotheses which can approximate a large number of input/outputmappings.

• The variance term warns us against an excessive complexity of theapproximator. This means that a class of too powerful hypotheses runsthe risk of being excessively sensitive to the noise affecting the trainingset; therefore, our class could contain the target but it could bepractically impossible to find it out on the basis of the available dataset.

Computational Intelligence Methods for Prediction – p. 40/83

Page 41: Computational Intelligence for Time Series Prediction

• In other terms, it is commonly said that an hypothesis with large bias butlow variance underfits the data while an hypothesis with low bias butlarge variance overfits the data.

• In both cases, the hypothesis gives a poor representation of the targetand a reasonable trade-off needs to be found.

• The task of the model designer is to search for the optimal trade-offbetween the variance and the bias term, on the basis of the availabletraining set.

Computational Intelligence Methods for Prediction – p. 41/83

Page 42: Computational Intelligence for Time Series Prediction

Bias/variance trade-off

complexity

generalizationerror

Bias

Variance

Underfitting Overfitting

Computational Intelligence Methods for Prediction – p. 42/83

Page 43: Computational Intelligence for Time Series Prediction

The learning procedureA learning procedure aims at two main goals:

1. to choose a parametric family of hypothesis h(x, α) which contains orgives good approximation of the unknown function f (structural

identification ).

2. within the family h(x, α), to estimate on the basis of the training set DN

the parameter αN which best approximates f (parametric identification ).

In order to accomplish that, a learning procedure is made of two nestedloops:

1. an external structural identification loop which goes through differentmodel structures

2. an inner parametric identification loop which searches for the bestparameter vector within the family structure.

Computational Intelligence Methods for Prediction – p. 43/83

Page 44: Computational Intelligence for Time Series Prediction

Parametric identificationThe parametric identification of the hypothesis is done according to ERM(Empirical Risk Minimization) principle where

αN = α(DN ) = arg minα∈Λ

MISEemp(α)

minimizes the empirical risk or training error

MISEemp(α) =

∑N

i=1 (yi − h(xi, α))2

N

constructed on the basis of the data set DN .

Computational Intelligence Methods for Prediction – p. 44/83

Page 45: Computational Intelligence for Time Series Prediction

Parametric identification (II)• The computation of αN requires a procedure of multivariate optimization

in the space of parameters.

• The complexity of the optimization depends on the form of h(·).

• In some cases the parametric identification problem may be an NP-hardproblem.

• Thus, we must resort to some form of heuristic search.

• Examples of parametric identification procedure are linear least-squaresfor linear models and backpropagated gradient-descent for feedforwardneural networks.

Computational Intelligence Methods for Prediction – p. 45/83

Page 46: Computational Intelligence for Time Series Prediction

Validation techniquesHow to measure MISE in a reliable way on a finite dataset? The most

common techniques to return an estimate MISE are

Testing: a testing sequence independent of DN and distributed according tothe same probability distribution is used to assess the quality. Inpractice, unfortunately, an additional set of input/output observations israrely available.

Holdout: The holdout method, sometimes called test sample estimation,partitions the data DN into two mutually exclusive subsets, the trainingset Dtr and the holdout or test set DNts

.

k-fold Cross-validation: the set DN is randomly divided into k mutuallyexclusive test partitions of approximately equal size. The cases notfound in each test partition are independently used for selecting thehypothesis which will be tested on the partition itself. The average errorover all the k partitions is the cross-validated error rate.

Computational Intelligence Methods for Prediction – p. 46/83

Page 47: Computational Intelligence for Time Series Prediction

The K-fold cross-validationThis is the algorithm in detail:

1. split the dataset DN into k roughly equal-sized parts.

2. For the kth part k = 1, . . . , K, fit the model to the other K − 1 parts of thedata, and calculate the prediction error of the fitted model whenpredicting the k-th part of the data.

3. Do the above for k = 1, . . . , K and average the K estimates of predictionerror.

Let k(i) be the part of DN containing the ith sample. Then thecross-validation estimate of the MISE prediction error is

MISECV =1

N

N∑

i=1

(yi − y−k(i)i )2 =

1

N

N∑

i=1

(

yi − h(xi, α−k(i))

)2

where y−k(i)i denotes the fitted value for the ith observation returned by the

model estimated with the k(i)th part of the data removed.

Computational Intelligence Methods for Prediction – p. 47/83

Page 48: Computational Intelligence for Time Series Prediction

10-fold cross-validationK = 10: at each iteration 90% of data are used for training and the remaining10% for the test.

90%

10%

Computational Intelligence Methods for Prediction – p. 48/83

Page 49: Computational Intelligence for Time Series Prediction

Leave-one-out cross validation• The cross-validation algorithm where K = N is also called the

leave-one-out algorithm.

• This means that for each ith sample, i = 1, . . . , N ,

1. we carry out the parametric identification, leaving that observationout of the training set,

2. we compute the predicted value for the ith observation, denoted byy−i

i

The corresponding estimate of the MISE prediction error is

MISELOO =1

N

N∑

i=1

(yi − y−ii )2 =

1

N

N∑

i=1

(yi − h(

xi, α−i)

)2

where α−i is the set of parameters returned by the parametric identificationperfomed on the training set with the ith sample set aside.

Computational Intelligence Methods for Prediction – p. 49/83

Page 50: Computational Intelligence for Time Series Prediction

Model selection• Model selection concerns the final choice of the model structure in the

set that has been proposed by model generation and assessed bymodel validation.

• In real problems, this choice is typically a subjective issue and is oftenthe result of a compromise between different factors, like the quantitativemeasures, the personal experience of the designer and the effortrequired to implement a particular model in practice.

• Here we will consider only quantitative criteria. Two are the possibleapproaches:

1. the winner-takes-all approach

2. the combination of estimators approach.

Computational Intelligence Methods for Prediction – p. 50/83

Page 51: Computational Intelligence for Time Series Prediction

Model selection

N

REALIZATION

STOCHASTIC PROCESS

VALIDATION

CLASSES of HYPOTHESIS

LEARNED MODEL

TRAINING SET

MODEL SELECTION

PARAMETRIC IDENTIFICATION

IDENTIFICATION

,,

, ,

,

,

STRUCTURAL

α?

ΛSΛ2Λ1

GN

1α1

N

α1

N

α2

N

α2

N

αN

s

αN

s

GN

2 GN

S

GN

2GN

1 GN

S

Computational Intelligence Methods for Prediction – p. 51/83

Page 52: Computational Intelligence for Time Series Prediction

Winner-takes-allThe best hypothesis is selected in the set {αs

N}, with s = 1, . . . , S, accordingto

s = arg mins=1,...,S

MISEs

A model with complexity s is trained on the whole dataset DN and used forfuture predictions.

Computational Intelligence Methods for Prediction – p. 52/83

Page 53: Computational Intelligence for Time Series Prediction

Winner-takes-all pseudo-code1. for s = 1, . . . , S: (Structural loop)

• for j = 1, . . . , N

(a) Inner parametric identification (for l-o-o):

αsN−1 = arg min

α∈Λs

i=1:N,i 6=j

(yi − h(xi, α))2

(b) ej = yj − h(xj , αsN−1)

• MISELOO(s) = 1N

∑N

j=1 e2j

2. Model selection: s = arg mins=1,...,S MISELOO(s)

3. Final parametric identification:αs

N = arg minα∈Λs

∑N

i=1(yi − h(xi, α))2

4. The output prediction model is h(·, αsN )

Computational Intelligence Methods for Prediction – p. 53/83

Page 54: Computational Intelligence for Time Series Prediction

Model combination• The winner-takes-all approach is intuitively the approach which should

work the best.

• However, recent results in machine learning show that the performanceof the final model can be improved not by choosing the model structurewhich is expected to predict the best but by creating a model whoseoutput is the combination of the output of models having differentstructures.

• The reason is that in reality any chosen hypothesis h(·, αN ) is only anestimate of the real target and, like any estimate, is affected by a biasand a variance term.

• Theoretical results on the combination of estimators show that thecombination of unbiased estimators leads an unbiased estimator withreduced variance.

• This principle is at the basis of approaches like bagging or boosting.

Computational Intelligence Methods for Prediction – p. 54/83

Page 55: Computational Intelligence for Time Series Prediction

Local modeling procedureThe learning of a local model in xq ∈ Rn can be summarized in these steps:

1. Compute the distance between the query xq and the training samplesaccording to a predefined metric.

2. Rank the neighbors on the basis of their distance to the query.

3. Select a subset of the k nearest neighbors according to the bandwidthwhich measures the size of the neighborhood.

4. Fit a local model (e.g. constant, linear,...).

Each of the local approaches has one or more structural (or smoothing)parameters that control the amount of smoothing performed.Let us focus on the bandwidth selection.

Computational Intelligence Methods for Prediction – p. 55/83

Page 56: Computational Intelligence for Time Series Prediction

The bandwidth trade-off: overfit

e

q

����

����

����

��

��

����

��

����

����

�������� �

���

����

����

��������

��

��������

����

��

������������

����

����

���������������������������������������������������������������������������������������������������������������������

�������������������������������

x

y

����

����

����

��

��

����

��

����

����

�������� �

���

����

���

���

��������

��

��������

����

��

������������

����

������

������

����

���������������������������������������������������������������������������������������������������������������������

�������������������������������

x

y

Too narrow bandwidth ⇒ overfitting ⇒ large prediction error e.In terms of bias/variance trade-off, this is typically a situation of high variance.

Computational Intelligence Methods for Prediction – p. 56/83

Page 57: Computational Intelligence for Time Series Prediction

The bandwidth trade-off: underfit

e

q

����

����

����

��

��

����

��

����

����

�������� �

���

����

��������

��

��������

����

��

������������

����

����

���������������������������������������������������������������������������������������������������������������������

�������������������������������

x

y

����

����

����

��

��

����

������

������

���

���������

������

����

���

���

��������

���

���

��

������������

��������

������

������ �

���

��������

������

������

����

���

���

���

���

������

������

��������

���������������������������������������������������������������������������������������������������������������������

�������������������������������

x

y

Too large bandwidth ⇒ underfitting ⇒ large prediction error e

In terms of bias/variance trade-off, this is typically a situation of high bias.

Computational Intelligence Methods for Prediction – p. 57/83

Page 58: Computational Intelligence for Time Series Prediction

Bandwidth and bias/variance trade-offMean Squared Error

1/Bandwith

FEW NEIGHBORSMANY NEIGHBORS

Bias

Variance

Underfitting Overfitting

Computational Intelligence Methods for Prediction – p. 58/83

Page 59: Computational Intelligence for Time Series Prediction

The PRESS statistic• Cross-validation can provide a reliable estimate of the algorithm

generalization error but it requires the training process to be repeated K

times, which sometimes means a large computational effort.

• In the case of linear models there exists a powerful statistical procedureto compute the leave-one-out cross-validation measure at a reducedcomputational cost

• It is the PRESS (Prediction Sum of Squares) statistic, a simple formulawhich returns the leave-one-out (l-o-o) as a by-product of theleast-squares.

Computational Intelligence Methods for Prediction – p. 59/83

Page 60: Computational Intelligence for Time Series Prediction

Leave-one-out for linear models

PARAMETRIC IDENTIFICATION ON N-1 SAMPLES

PUT THE j-th SAMPLE ASIDE

TEST ON THE j-th SAMPLE

PARAMETRIC IDENTIFICATION

ON N SAMPLESN TIMES

TRAINING SET

PRESS STATISTIC

LEAVE-ONE-OUT

The leave-one-out error can be computed in two equivalent ways: the slowestway (on the right) which repeats N times the training and the test procedure;the fastest way (on the left) which performs only once the parametricidentification and the computation of the PRESS statistic.

Computational Intelligence Methods for Prediction – p. 60/83

Page 61: Computational Intelligence for Time Series Prediction

The PRESS statistic• This allows a fast cross-validation without repeating N times the

leave-one-out procedure. The PRESS procedure can be described asfollows:

1. we use the whole training set to estimate the linear regressioncoefficients

β = (XT X)−1XT Y

2. This procedure is performed only once on the N samples andreturns as by product the Hat matrix

H = X(XT X)−1XT

3. we compute the residual vector e, whose jth term is ej = yj − xTj β,

4. we use the PRESS statistic to compute elooj as

elooj =

ej

1 − Hjj

where Hjj is the jth diagonal term of the matrix H.

Computational Intelligence Methods for Prediction – p. 61/83

Page 62: Computational Intelligence for Time Series Prediction

The PRESS statisticThus, the leave-one-out estimate of the local mean integrated squared erroris:

MISELOO =1

N

N∑

i=1

{ yi − yi

1 − Hii

}2

Note that PRESS is not an approximation of the loo error but simply a fasterway of computing it.

Computational Intelligence Methods for Prediction – p. 62/83

Page 63: Computational Intelligence for Time Series Prediction

Selection of the number of neighbours• For a given query point xq, we can compute a set of predictions

yq(k) = xTq β(k)

, together with a set of associated leave-one-out error vectors

MISELOO(k) for a number of neighbors ranging in [kmin, kmax].

• If the selection paradigm, frequently called winner-takes-all, is adopted,the most natural way to extract a final prediction yq, consists incomparing the prediction obtained for each value of k on the basis of theclassical mean square error criterion:

yq = xTq β(k), with k = arg min

kMISELOO(k)

Computational Intelligence Methods for Prediction – p. 63/83

Page 64: Computational Intelligence for Time Series Prediction

Local Model combination• As an alternative to the winner-takes-all paradigm, we can use a

combination of estimates.

• The final prediction of the value yq is obtained as a weighted average ofthe best b models, where b is a parameter of the algorithm.

• Suppose the predictions yq(k) and the loo errors MISELOO(k) have beenordered creating a sequence of integers {ki} so that

MISELOO(ki) ≤ MISELOO(kj), ∀i < j. The prediction of yq is given by

yq =

∑b

i=1 ζiyq(ki)∑b

i=1 ζi

,

where the weights are the inverse of the mean square errors:

ζi = 1/MISELOO(ki).

Computational Intelligence Methods for Prediction – p. 64/83

Page 65: Computational Intelligence for Time Series Prediction

One step-ahead and iterated prediction• Once a model of the embedding mapping is available, it can be used for

two objectives: one-step-ahead prediction and iterated prediction.

• In one-step-ahead prediction, the n previous values of the series areavailable and the forecasting problem can be cast in the form of ageneric regression problem

• In literature a number of supervised learning approaches have beenused with success to perform one-step-ahead forecasting on the basisof historical data.

Computational Intelligence Methods for Prediction – p. 65/83

Page 66: Computational Intelligence for Time Series Prediction

One step-ahead prediction

f

ϕt-2

z -1

z -1

z -1

ϕt-3

ϕt-n

ϕt-1

z -1

ϕt

The approximator f returns the prediction of the value of the time series attime t + 1 as a function of the n previous values (the rectangular boxcontaining z−1 represents a unit delay operator, i.e., ϕt−1 = z−1ϕt).

Computational Intelligence Methods for Prediction – p. 66/83

Page 67: Computational Intelligence for Time Series Prediction

Multi-step ahead prediction• The prediction of the value of a time series H > A steps ahead is called

H-step-ahead prediction.

• We classify the methods for H-step-ahead prediction according to twofeatures: the horizon of the training criterion and the single-output ormulti-output nature of the predictor.

Computational Intelligence Methods for Prediction – p. 67/83

Page 68: Computational Intelligence for Time Series Prediction

Multi-step ahead prediction strategiesThe most common strategies are

1. Iterated: the model predicts h steps ahead by iterating a one-step-aheadpredictor whose parameters are optimized to minimize the training erroron one-step-ahead forecast (one-step-ahead training criterion).

2. Iterated strategy where parameters are optimized to minimize thetraining error on the iterated htr-step-ahead forecast (htr-step-aheadtraining criterion) where 1 < htr ≤ H.

3. Direct: the model makes a direct forecast at time t + h − 1, h = 1, . . . , H

by modeling the time series in a multi-input single-output form

4. Direc: direct forecast but the input vector is extended at each step withpredicted values.

5. MIMO: the model returns a vectorial forecast by modeling the timeseries in a multi-input multi-output form

Computational Intelligence Methods for Prediction – p. 68/83

Page 69: Computational Intelligence for Time Series Prediction

Iterated (or recursive) prediction• In the case of iterated prediction, the predicted output is fed back as

input for the next prediction.

• Here, the inputs consist of predicted values as opposed to actualobservations of the original time series.

• As the feedback values are typically distorted by the errors made by thepredictor in previous steps, the iterative procedure may produceundesired effects of accumulation of the error.

• Low performance is expected in long horizon tasks. This is due to thefact that they are essentially models tuned with a one-step-aheadcriterion which is not capable of taking temporal behavior into account.

Computational Intelligence Methods for Prediction – p. 69/83

Page 70: Computational Intelligence for Time Series Prediction

Iterated prediction

f

ϕt-2

z -1

z -1

z -1

z -1

ϕt-3

ϕt-n

ϕt-1

z -1

ϕt

The approximator f returns the prediction of the value of the time series attime t + 1 by iterating the predictions obtained in the previous steps (therectangular box containing z−1 represents a unit delay operator, i.e.,ϕt−1 = z−1ϕt).

Computational Intelligence Methods for Prediction – p. 70/83

Page 71: Computational Intelligence for Time Series Prediction

Iterated with h-step training criterion• This strategy adopts one-step-ahead predictors but adapts the model

selection criterion in order to take into account the multi-step-aheadobjective.

• Methods like Recurrent Neural Networks belong to such class. Theirrecurrent architecture and the associated training algorithm (temporalbackpropagation) are suitable to handle the time-dependent nature ofthe data.

• In [?] we proposed an adaptation of the Lazy Learning algorithm wherethe number of neighbors is optimized in order to minimize theleave-one-out error over an horizon larger than one. This techniqueranked second in the 1998 KULeuven Time Series competition.

• A similar technique has been proposed by [?] who won the competition.

Computational Intelligence Methods for Prediction – p. 71/83

Page 72: Computational Intelligence for Time Series Prediction

Direct strategy• The Direct strategy [?, ?, ?] learns independently H models fh

ϕt+h = fh(ϕt, . . . , ϕt−n+1) + wt+h

with t ∈ {n, . . . , N − H} and h ∈ {1, . . . , H} and returns a multi-stepforecast by concatenating the H predictions.

Computational Intelligence Methods for Prediction – p. 72/83

Page 73: Computational Intelligence for Time Series Prediction

Direct strategy• Since the Direct strategy does not use any approximated values to

compute the forecasts, it is not prone to any accumulation of errors,since each model is tailored for the horizon it is supposed to predict.Notwithstanding, it has some weaknesses.

• Since the H models are learned independently no statisticaldependencies between the predictions yN+h[?, ?, ?] is considered.

• Direct methods often require higher functional complexity [?] thaniterated ones in order to model the stochastic dependency between twoseries values at two distant instants [?].

• This strategy demands a large computational time since the number ofmodels to learn is equal to the size of the horizon.

• Different machine learning models have been used to implement theDirect strategy for multi-step forecasting tasks, for instance neuralnetworks [?], nearest neighbors [?] and decision trees [?].

Computational Intelligence Methods for Prediction – p. 73/83

Page 74: Computational Intelligence for Time Series Prediction

DirRec strategy• The DirRec strategy [?] combines the architectures and the principles

underlying the Direct and the Recursive strategies.

• DirRec computes the forecasts with different models for everyhorizon (like the Direct strategy) and, at each time step, it enlarges theset of inputs by adding variables corresponding to the forecasts of theprevious step (like the Recursive strategy).

• Unlike the previous strategies, the embedding size n is not the same forall the horizons. In other terms, the DirRec strategy learns H models fh

from the time series [y1, . . . , yN ] where

yt+h = fh(yt+h−1, . . . , yt−n+1) + wt+h

with t ∈ {n, . . . , N − H} and h ∈ {1, . . . , H}.

• The technique is prone to the curse of dimensionality. The use of featureselection is recommended for large h.

Computational Intelligence Methods for Prediction – p. 74/83

Page 75: Computational Intelligence for Time Series Prediction

MIMO strategy• This strategy [?, ?] (also known as Joint strategy [?]) avoids the simplistic

assumption of conditional independence between future values made bythe Direct strategy [?, ?] by learning a single multiple-output model

[yt+H , . . . , yt+1] = F (yt, . . . , yt−n+1) + w

where t ∈ {n, . . . , N − H}, F : Rd → RH is a vector-valued function [?],and w ∈ RH is a noise vector with a covariance that is not necessarilydiagonal [?].

• The forecasts are returned in one step by a multiple-output model F

where

[yt+H , . . . , yt+1] = F (yN , . . . , yN−n+1)

Computational Intelligence Methods for Prediction – p. 75/83

Page 76: Computational Intelligence for Time Series Prediction

MIMO strategy• The rationale of the MIMO strategy is to model, between the predicted

values, the stochastic dependency characterizing the time series. Thisstrategy avoids the conditional independence assumption made by theDirect strategy as well as the accumulation of errors which plagues theRecursive strategy. So far, this strategy has been successfully applied toseveral real-world multi-step time series forecasting tasks [?, ?, ?, ?].

• However, the wish to preserve the stochastic dependencies constrainsall the horizons to be forecasted with the same model structure. Sincethis constraint could reduce the flexibility of the forecasting approach [?],a variant of the MIMO strategy has been proposed in [?, ?] .

Computational Intelligence Methods for Prediction – p. 76/83

Page 77: Computational Intelligence for Time Series Prediction

Validation of time series methods• The huge variety of strategies and algorithms that can be used to infer a

predictor from observed data asks for a rigorous procedure ofcomparison and assessment.

• Assessment demands benchmarks and benchmarking procedure.

• Benchmarks can be defined by using• Simulated data obtained by simulating AR, NAR and other stochastic

processes. This is particular useful for validating theoreticalproperties in terms of bias/variance.

• Public domain benchmarks, like the one provided by Time SeriesCompetitions.

• Real measured data

Computational Intelligence Methods for Prediction – p. 77/83

Page 78: Computational Intelligence for Time Series Prediction

Competitions• Santa Fe Time Series Prediction and Analysis Competition (1994) [?]:

• International Workshop on Advanced Black-box techniques for nonlinearmodeling Competition (Leuven, Belgium; 1998)

• NN3 competition [?]: 111 monthly time series drawn from homogeneouspopulation of empirical business time series.

• NN5 competition [?]: 111 time series of the daily retirement amountsfrom independent cash machines at different, randomly selectedlocations across England.

Computational Intelligence Methods for Prediction – p. 78/83

Page 79: Computational Intelligence for Time Series Prediction

MLG projects on forecastingWireless sensorAnesthesiaCar market prediction

Computational Intelligence Methods for Prediction – p. 79/83

Page 80: Computational Intelligence for Time Series Prediction

Open-source software

Computational Intelligence Methods for Prediction – p. 80/83

Page 81: Computational Intelligence for Time Series Prediction

All that we didn’t have time to discuss

Computational Intelligence Methods for Prediction – p. 81/83

Page 82: Computational Intelligence for Time Series Prediction

Perspectives

Computational Intelligence Methods for Prediction – p. 82/83

Page 83: Computational Intelligence for Time Series Prediction

Suggestions for PhD topics

Computational Intelligence Methods for Prediction – p. 83/83