Search

Search papers and lessons

Are Transformers Effective for Time Series Forecasting?

Ailing Zeng, Muxi Chen, Lei Zhang et al. · 2022

This 2022 paper shows that one-layer linear models beat several Transformer forecasters on nine long-horizon benchmarks, which questions whether self-attention helps time series.

On this page

  • Colour = topic mix
  • Probability
  • Calculus
  • Discrete math
  • Linear algebra
  • Neural network basics
  • Architectures
  • ReadReady to readNot yet

TL;DR

The paper asks whether Transformers really help with long-term time series forecasting. It answers no, at least on the standard benchmarks: a one-layer linear model, called LTSF-Linear, beats the Transformer forecasters it tests on nine real datasets. The authors argue that self-attention is permutation-invariant, so it throws away the order that matters most in a time series.

Builds on: Transformer, Multi-Head Attention, Positional Encoding, Linear Regression, Moving Average Model · Leads to: a new baseline for long-term forecasting, and a call to recheck Transformer claims on other time series tasks

Why it mattered

From 2019 to 2022, a series of papers proposed Transformer variants for long-term forecasting: LogTrans, Informer, Autoformer, Pyraformer and FEDformer. Each reported gains over earlier neural methods. This paper showed that the baselines in those comparisons were iterated forecasters, which accumulate error, while the Transformers were trained to predict the whole future at once. When the linear model was given the same direct strategy, it matched or beat the Transformers. After this paper, a simple linear model became the baseline that a new long-term forecaster should be compared against.

The problem

A forecaster takes the last LL values of a series (the look-back window) and predicts the next TT values (the horizon). For long horizons, there are two strategies. Iterated multi-step forecasting trains a one-step model and feeds its own predictions back in; it has small variance but suffers error accumulation. Direct multi-step forecasting trains the model to output all TT values at once.

Transformers were built for words and image patches, where the meaning of a pair of tokens matters more than their exact order. The paper argues that a numeric series is different: the relations among a continuous run of points are the signal, and self-attention, which treats its input as an unordered set once positional encodings are added, loses some of that order. The question is whether this loss matters in practice.

How it works

The paper's pipeline has three stages: a standard Transformer forecaster, a set of linear replacements, and a set of tests. Here is the linear model traced on one variate with a tiny look-back window.

  1. Take the history. Let the look-back window be L=3L = 3 values: [2,4,6][2, 4, 6]. The model sees these in order. Check: the input has three numbers, oldest first.
  2. Apply one linear layer. For each output step, multiply the history by a row of weights and add up. Here the row for the first future step is [0.2,0.3,0.5][0.2, 0.3, 0.5], so the output is 0.2×2+0.3×4+0.5×6=4.60.2 \times 2 + 0.3 \times 4 + 0.5 \times 6 = 4.6. Check: each output is a weighted sum of the whole window, so order is kept because each weight belongs to a fixed position.
  3. Predict all horizon steps at once. The layer has one row per future step. With a second row [0.1,0.1,0.8][0.1, 0.1, 0.8] the second output is 5.45.4. This is the direct strategy: both values come from the same input in one pass. Check: no output feeds back into the input.
  4. Optionally, remove the trend. DLinear first splits the input into a trend and a remainder. The trend is a moving average of the history; the remainder is the input minus that trend. Two linear layers forecast the two parts, and their outputs are added. Check: the two parts add back to the original input.
  5. Optionally, subtract the last value. NLinear subtracts the most recent value from the window before the linear layer and adds it back afterwards. This handles series whose level shifts over time. Check: the subtraction and the addition cancel.

Each linear layer has T×LT \times L weights per variate. The paper's linear models do not model correlations among variates, so they learn no relations between series.

flowchart LR
  H[look-back window of L values] --> D{decompose?}
  D -->|DLinear| TR[trend: moving average]
  D -->|DLinear| RM[remainder: input minus trend]
  D -->|Vanilla or NLinear| W1[one linear layer]
  TR --> W2[linear layer]
  RM --> W3[linear layer]
  W2 --> ADD[sum]
  W3 --> ADD
  W1 --> OUT[T future values]
  ADD --> OUT

The math

Let a series have CC variates, with values XitX_i^t for variate ii at time tt. The look-back window is X={X1t,…,XCt}t=1L\mathcal{X} = \{X^t_1, \dots, X^t_C\}_{t=1}^{L}, and the forecast is X^={X^1t,…,X^Ct}t=L+1L+T\hat{\mathcal{X}} = \{\hat{X}^t_1, \dots, \hat{X}^t_C\}_{t=L+1}^{L+T}. The paper's model for one variate is

X^i=WXi,W∈RT×L,\hat{X}_i = W X_i, \qquad W \in \mathbb{R}^{T \times L},

where Xi∈RLX_i \in \mathbb{R}^{L} is the input window and X^i∈RT\hat{X}_i \in \mathbb{R}^{T} is the prediction. Training minimises the mean squared error between X^i\hat{X}_i and the true future, which is the usual squared-error loss for regression.

Step 3 in symbols: one matrix does the whole horizon

Row jj of WW is the weight vector for future step jj. So x^L+j=∑k=1LWjkxk\hat{x}_{L+j} = \sum_{k=1}^{L} W_{jk} x_k. Each output is a linear function of the window, and the matrix holds all TT outputs at once. For L=96L = 96 and T=720T = 720, that is 720×96=69,120720 \times 96 = 69{,}120 weights per variate.

Step 4 in symbols: decomposition

Let MA(x)\mathrm{MA}(x) be a moving average of the window. Then the trend is xtrend=MA(x)x_{\text{trend}} = \mathrm{MA}(x) and the remainder is xseasonal=x−xtrendx_{\text{seasonal}} = x - x_{\text{trend}}. DLinear forecasts x^=Wtxtrend+Wsxseasonal\hat{x} = W_t x_{\text{trend}} + W_s x_{\text{seasonal}}, so WtW_t and WsW_s are learned separately.

Step 5 in symbols: subtracting the last value

NLinear subtracts the last input value xLx_L from the window, applies WW, and adds xLx_L back: x^=W(x−xL1)+xL1\hat{x} = W(x - x_L \mathbf{1}) + x_L \mathbf{1}, where 1\mathbf{1} is a vector of ones. Only the differences from the last value are passed through the layer.

Worked examples

Example
1. Tiny: one linear forecast by hand
  1. Window x=[2,4,6]x = [2, 4, 6] and first row w=[0.2,0.3,0.5]w = [0.2, 0.3, 0.5].
  2. Multiply each value by its weight: 0.2×2=0.40.2 \times 2 = 0.4, 0.3×4=1.20.3 \times 4 = 1.2, 0.5×6=3.00.5 \times 6 = 3.0.
  3. Add: 0.4+1.2+3.0=4.60.4 + 1.2 + 3.0 = 4.6.

The forecast for that horizon step is 4.6. The weights put most of their mass on the latest value, which is what a series with momentum needs.

Example
2. Standard: checking the paper's improvement column

The paper's Table 2 gives, for Exchange-Rate at horizon 96, a DLinear MSE of 0.081 and a best Transformer MSE of 0.148 (FEDformer). The IMP column shows 45.27 percent.

  1. Compute the gap: 0.148−0.081=0.0670.148 - 0.081 = 0.067.
  2. Divide by the Transformer value: 0.067/0.148=0.45270.067 / 0.148 = 0.4527.
  3. Convert to a percentage: 45.27 percent.

The computed value matches the table, so the printed numbers and the column agree for this row.

Example
3. Realistic: does shuffling the input hurt?

Table 5 shuffles the input order on Exchange-Rate at horizon 96 and compares MSE before and after.

  1. Linear model: original MSE 0.080, shuffled MSE 0.133.
  2. Increase: 0.133−0.080=0.0530.133 - 0.080 = 0.053.
  3. Relative increase: 0.053/0.080=0.66250.053 / 0.080 = 0.6625, so about 66 percent worse.
  4. FEDformer on the same row: original 0.161, shuffled 0.160, a slight decrease.
  5. The Transformer's result does not depend on the order of the input, which is the paper's point about permutation invariance. The linear model does depend on order, and the paper reads that as a sign it uses order properly.

Try it: on Electricity at horizon 96, the linear MSE is 0.140 and the best Transformer MSE is 0.193. By what percentage is the linear model better? Answer: (0.193−0.140)/0.193=0.053/0.193≈0.2746(0.193 - 0.140) / 0.193 = 0.053 / 0.193 \approx 0.2746, about 27.5 percent. The table prints 27.40 percent, a small gap from rounding the printed MSE values to three decimals.

Results

All numbers below are copied from the paper's Table 2 unless noted. Lower MSE is better. The paper evaluates nine datasets: ETTh1, ETTh2, ETTm1, ETTm2, Traffic, Electricity, Weather, ILI and Exchange-Rate.

  • Electricity, horizon 96. DLinear MSE 0.140 and MAE 0.237. FEDformer MSE 0.193. Informer MSE 0.274.
  • Traffic, horizon 96. Linear MSE 0.410 and MAE 0.282. FEDformer MSE 0.587 and MAE 0.366.
  • Exchange-Rate, horizon 96. DLinear MSE 0.081. FEDformer MSE 0.148. Informer MSE 0.847.
  • Improvement column. The paper's IMP column ranges from 0.80 percent (ETTh1, horizon 96) to 47.86 percent (ILI, horizon 24). The introduction's summary of "20 to 50 percent" is looser than the table, so use the table. Some IMP values cannot be reproduced from the printed MSE values to two digits; for example ETTh1 at horizon 96 prints 0.80 percent, but the printed DLinear value 0.375 against the best Transformer's 0.376 gives about 0.3 percent.
  • Look-back window (Figure 4). On Traffic and Electricity at horizon 720, as the window grows, Transformer error stays flat or rises, while linear error falls. The paper reads this as Transformers overfitting temporal noise.
  • Input order (Table 5). Shuffling the input hurts the linear model badly (average drop 27.26 percent on Exchange-Rate) and leaves the Transformers almost unchanged.
  • Simplifying Informer (Table 4). The paper strips Informer step by step, at look-back 96. On Exchange-Rate at horizon 96, Informer's MSE is 0.847, the attention-replaced version 1.003, the embedding-plus-linear version 0.173, and the single linear layer 0.084. The middle step is worse than Informer, so the trend is not monotone, but the simplest model is the best of the four.

Limits. The claims hold for these benchmarks, with a look-back window of 96; the paper's appendix also reports the Transformers at a look-back of 336, where the comparison is closer to fair. The paper does not show that Transformers fail on all time series tasks, and it explicitly leaves other tasks, such as anomaly detection, to future work. Shuffling results show that the Transformers ignore order on Exchange-Rate, which the authors take as overfitting to noise, not as proof of a general limit.

Reading guide

  1. Abstract and Section 1 (Introduction). Needs Transformer for the architecture being challenged, and Linear Regression for the baseline.
  2. Section 2 (Problem formulation). Needs Autoregressive Model for iterated forecasting, and Mean Squared Error for the metric.
  3. Section 3 (Transformer-based solutions). Needs Multi-Head Attention and Positional Encoding to follow the design elements the authors list.
  4. Section 4 (The baseline). Needs Linear Regression and Moving Average Model for DLinear's decomposition.
  5. Section 5 (Experiments). Read Table 2 for the main claim and Tables 3 to 5 for the analyses.

Check yourself

QuestionWhat is the key difference between iterated and direct multi-step forecasting?Show answer

Iterated forecasting trains a one-step model and feeds its own predictions back in, so errors can accumulate. Direct forecasting trains the model to output all future steps from the same input in one pass, avoiding that feedback.

QuestionA linear model has look-back L=4L = 4 and horizon T=2T = 2. How many weights does its matrix WW have?Show answer

W∈RT×LW \in \mathbb{R}^{T \times L} has 2×4=82 \times 4 = 8 weights per variate.

QuestionWhy does the paper shuffle the input and compare Transformers with a linear model?Show answer

If a model uses the order of the series, shuffling should hurt it. The paper finds that the linear model gets much worse, while the Transformers barely change, which suggests the Transformers are not using temporal order on that dataset.

QuestionOn Exchange-Rate at horizon 96, the linear MSE is 0.081 and FEDformer's is 0.148. What is the relative improvement?Show answer

(0.148−0.081)/0.148=0.067/0.148≈0.4527(0.148 - 0.081) / 0.148 = 0.067 / 0.148 \approx 0.4527, about 45 percent. This matches the paper's IMP value of 45.27 percent for that row.

QuestionWhy does DLinear split the input into a trend and a remainder before applying linear layers?Show answer

A moving average extracts the slow trend, and the remainder holds the seasonal and noisy parts. Each part gets its own linear layer, so the model can learn a different mapping for the trend and the seasonal pattern. The paper hypothesises that long-term forecasting works mainly for series with a clear trend and periodicity, which is the structure this split makes explicit.

Sources

Read the full paper

Ailing Zeng, Muxi Chen, Lei Zhang et al., 2022. arXiv:2205.13504