TL;DR
DeepAR forecasts thousands of related time series with one shared recurrent network. For each future step it predicts a whole probability distribution, so a forecast can say "between 3 and 9 units with 80 percent confidence" rather than just "6". The paper reports accuracy gains of around 15 percent over the forecasting methods of its day on several sales and utility datasets.
Builds on: Autoregressive Model, Long Short-Term Memory, Gaussian (Normal) Distribution, Negative Binomial Distribution · Leads to: Chronos: Learning the Language of Time Series, which applies language-model-style methods to time series
Why it mattered
Demand forecasting is a daily job for retailers: how many units of each product will sell next week, so the right stock is in the right warehouse. Before DeepAR, most forecasters fitted a separate small model to each series, chosen and tuned by hand. DeepAR showed that one global network trained on all series at once could beat those per-series methods on the same data, and that it could forecast items with little or no history by borrowing from similar items.
The idea has lasted. Amazon's GluonTS toolkit ships a DeepAR estimator, and Amazon SageMaker offers DeepAR as a built-in forecasting algorithm. Its core move, a global autoregressive network that outputs distribution parameters, became a common template for later neural forecasters. The classical methods it was compared against, Box and Jenkins models from the late 1960s and exponential smoothing, each fit one series at a time.
The problem
A classical forecaster works on one series at a time. It assumes a shape (trend, seasonality, autocorrelation), fits a few parameters to that one history, and projects forward. That breaks down in three ways that the paper cares about.
- Many series are short, intermittent or erratic. Many items sell zero units in most weeks, and a classical model fitted to such a history is nearly guesswork.
- Sales volumes follow a power law. A few items sell thousands of units and most sell a handful. The paper shows that the distribution of sales velocity across millions of Amazon items is an approximate power law over a few orders of magnitude, so a model trained on all items sees very different scales. A Power Law is a relation where doubling the input multiplies the output by a fixed factor.
- Decisions need uncertainty. Ordering stock means balancing the cost of too little against too much, which depends on the whole range of outcomes, not on a point forecast.
The paper asks: can one network learn from all series together, handle counts and wide scale differences, and output calibrated distributions?
How it works
Here is the pipeline in the order it runs, for one item in a large set of items.
flowchart LR A["history z and covariates x"] --> B["divide z by scale nu"] B --> C["LSTM state h"] C --> D["network outputs o"] D --> E["softplus gives mu and alpha"] E --> F["negative binomial distribution"] F --> G["sample next value, feed back"]
-
Start with many related series. Each item has a weekly sales history, plus covariates such as product category, week of year and whether it is on promotion. The model learns from all items at once, so a new item with little history can borrow from its neighbours.
-
Choose a scale for each item. The paper uses the average of the item's observed history, plus 1. The formula is nu_i = 1 + (1/t_0) times the sum of the observed values. Check: if the history is 2, 0 and 4, the average is 2 and nu = 3.
-
Divide the lagged value by the scale before the network sees it. The network's input at each step includes the previous value, so the network works on values near 1 whether the item sells 2 units or 2000. Check: a previous value of 4 becomes 4 divided by 3, about 1.33.
-
Run the LSTM. An LSTM cell takes the scaled previous value, the covariates and its own previous state, and produces a new hidden state h. Information about the history is carried forward in h, which is how the model sees a long past without a hand-built lag structure.
-
Turn the output into distribution parameters. The network outputs two raw numbers, o_mu and o_alpha. A Softplus function keeps each one positive. The mean is mu = nu times softplus(o_mu), which multiplies the scale back in. The shape is alpha = softplus(o_alpha) divided by the square root of nu. Check: if both raw outputs are 0, softplus(0) is about 0.69, so with nu = 3 the mean is about 2.08.
-
Score the network against the truth. The distribution says how probable the actual next value was. Training adds up these log-probabilities over all time steps and all items, and Stochastic Gradient Descent nudges the weights to raise that total. Windows are sampled with probability proportional to nu, so large items are seen as often as their size warrants.
-
Forecast by sampling. At prediction time the true values are unknown after the forecast start. The model draws one value from its distribution, feeds that value back in as the next input, and repeats across the horizon. One such run is one sample path. The paper draws 200 paths per series.
-
Read the answer from the paths. To forecast a total over several weeks, sum each path over those weeks, then take quantiles of the 200 sums. Because the paths are joint samples, the quantiles of sums are consistent with the uncertainty that builds up over time.
The math
Definition. Let z_{i,t} be the value of series i at time t, and x_{i,t} its covariates. The model writes the joint forecast distribution as a product of one-step distributions:
Here h_{i,t} is the hidden state of the recurrent network, theta is the set of parameters that the likelihood needs, and ell is the chosen likelihood. Capital Theta stands for all the network weights.
Step 2 in symbols: the scale
The average of the observed values, plus one, is the item's scale. The "plus one" keeps the scale positive for items whose history is all zeros.
Step 3 in symbols: the scaled input
The network reads z_{i,t-1} divided by nu_i. The lagged value is therefore close to 1 for every item, which keeps the activations in their working range.
Step 5 in symbols: the negative binomial
For count data the paper uses a negative binomial likelihood with mean mu and shape alpha:
Gamma is the gamma function, a generalised factorial. In this parameterisation the variance is
so alpha controls how much the variance exceeds the mean. As alpha goes to 0 the distribution approaches a Poisson with variance equal to its mean.
The scaling of the parameters is
where log(1 + e^x) is the softplus function. For real-valued data the paper uses a Gaussian with mu = w_mu transposed h plus b_mu and sigma equal to softplus of its own affine output.
Plot of softplus against ReLU, the two functions that keep a raw output positive:
- softplus
- ReLU
Step 6 in symbols: the training objective
This is the log-likelihood of the observed data under the model, the quantity that Maximum Likelihood Estimation maximises. No latent variables are involved, so the sum can be optimised directly.
Step 7 in symbols: the forecast quantile loss
To score a quantile rho of a span sum Z, the paper uses
where I is 1 when its condition holds and 0 otherwise. The loss is zero when the predicted quantile equals the truth. Note the pairing of weights in the printed formula: an over-prediction (Ẑ above Z) is weighted by rho and an under-prediction by 1 minus rho. Most pinball-loss references use the opposite pairing for a given quantile, so check the convention before reusing this formula.
Worked examples
- Take a mean of mu = 3 and a shape of alpha = 0.5.
- Compute mu squared: 3 times 3 equals 9.
- Multiply by alpha: 9 times 0.5 equals 4.5.
- Add the mean: 3 plus 4.5 equals 7.5.
So Var[z] = 7.5. The variance is more than twice the mean, which is the overdispersion that makes this distribution suit sales counts better than a Poisson, whose variance would be 3.
Use the history 2, 0, 4 for an item, so the average is 2.
- Compute the scale: nu = 1 plus 2 equals 3.
- Set the raw network outputs to 0 for this step, so o_mu = 0 and o_alpha = 0.
- Evaluate softplus(0) = log(1 + e^0) = log 2, which is about 0.693.
- Compute the mean: mu = 3 times 0.693, which is about 2.08.
- Compute the shape: alpha = 0.693 divided by the square root of 3, which is about 0.693 divided by 1.732, giving about 0.400.
- Compute the mean squared: 2.08 squared is about 4.32.
- Compute the variance: 2.08 plus 4.32 times 0.400, which is 2.08 plus 1.73, giving about 3.81.
The predicted distribution for this step has mean about 2.08 and variance about 3.81. The scale did its job: the output lives on the item's own scale, not on a scale of 1.
A retailer's total sales for the next span are Z = 10 units. Two forecasts for the 0.9 quantile are given: 13 and 8. Compute the loss for each, with rho = 0.9.
- For the forecast 13: the difference is 13 minus 10, which is 3.
- The forecast is above the truth, so the indicator for "forecast greater than truth" is 1 and the other is 0.
- The bracket is 0.9 times 1 minus 0.1 times 0, which is 0.9.
- Multiply: 2 times 3 times 0.9 gives 5.4.
- For the forecast 8: the difference is 8 minus 10, which is minus 2.
- The forecast is at or below the truth, so the second indicator is 1: the bracket is 0 minus 0.1 times 1, which is minus 0.1.
- Multiply: 2 times minus 2 times minus 0.1 gives 0.4.
The loss is 5.4 for the high forecast and 0.4 for the low one. Under the printed formula, the over-forecast carries the weight rho = 0.9, so this example shows the formula's weighting, not the usual pinball-loss intuition in which a 0.9 quantile is penalised more for falling below the truth.
Try it: the 0.5 quantile forecast is 18 and the truth is Z = 20. Compute L with rho = 0.5.
Answer: the difference is 18 minus 20, which is minus 2. The forecast is at or below the truth, so the bracket is 0 minus 0.5 times 1, which is minus 0.5. Multiply: 2 times minus 2 times minus 0.5 equals 2.
Results
The paper evaluates on five datasets. Three are public: parts (1046 monthly series of 50 steps, from a car company), electricity (370 hourly customer series) and traffic (963 hourly lane occupancy series). Two are Amazon weekly sales: ec-sub and ec, with ec containing 534,884 series. Forecasts are for 52 weeks on the sales data.
Table 1 normalises every method to a baseline, so 1.00 means the baseline and lower is better. The average over all lead times is:
| Dataset | DeepAR | Best other method | Its average |
|---|---|---|---|
| parts | 0.94 | rnn-negbin, 0.99 | 0.99 |
| ec-sub | 0.77 | ISSM (baseline), 1.00 | 1.00 |
| ec | 0.85 | rnn-negbin, 0.93 | 0.93 |
On ec-sub, the Gaussian RNN averages 1.21, worse than the baseline. On parts, the RNN with a negative binomial but without the scaling and weighted sampling averages 0.99, close to DeepAR's 0.94.
Table 2 compares point forecasts with the matrix factorisation method of an earlier paper. On electricity DeepAR has normalised deviation 0.07 against 0.16 for MatFact, and RMSE 1.00 against 1.15. On traffic it is 0.17 against 0.20 and RMSE 0.42 against 0.43.
The abstract claims accuracy improvements of around 15 percent over state-of-the-art methods. In the table's average column, DeepAR beats the best other method by about 5 percent on parts (0.94 against 0.99), 9 percent on ec (0.85 against 0.93) and 23 percent on ec-sub (0.77 against 1.00). The abstract's figure is a summary across datasets and lead times, so read it as approximate.
Limits. The paper names only parts, electricity and traffic as public datasets, so the Amazon sales comparisons cannot be checked by rerunning the public data. The tables show single numbers without error bars, so it is not possible to see how much they would move under a different random seed. Hyperparameters were chosen on a 90/10 split of the training range, and the paper notes that this procedure could still overfit the hyperparameters. Calibration is shown with coverage plots, where the paper says calibration improves on ISSM overall; these plots are not summarised as a single number.
Tradeoffs. DeepAR needs many related series to learn from. The paper's conclusion says it also applies to medium-size datasets of a few hundred series, but the large gains show up on big collections. A full training and prediction run on the 500K-series ec dataset takes under 10 hours on one GPU instance, and each forecast draws 200 sample paths. Use it when you have many related series, want calibrated intervals and can afford the compute. Prefer a classical method for a single short series, or when interpretability of each component matters more than accuracy.
Reading guide
- Section 1, Introduction: the power-law problem and the argument for global models. Needs Power Law and the idea of a Recurrent Neural Network.
- Section 2, Related Work: classical models such as ARIMA and exponential smoothing, and count-data likelihoods. No prerequisite lesson is needed beyond Gaussian (Normal) Distribution and Negative Binomial Distribution.
- Section 3.1, Likelihood model: the Gaussian and negative binomial parameterisations. Needs Negative Binomial Distribution and Softplus.
- Section 3.2, Training: the log-likelihood objective and the discrepancy with Teacher Forcing, where the paper notes Scheduled Sampling did not help. Needs Maximum Likelihood Estimation and Stochastic Gradient Descent.
- Section 3.3, Scale handling: the scale nu_i and weighted sampling. Needs the scaling idea from this lesson.
- Section 3.4, Features: covariates and Embedding Layer for the item identity.
- Section 4, Experiments: the datasets, the tables and the comparisons. Results above.
- Section 5, Conclusion, and the supplement for the metrics, hyperparameters and missing observations.
Read next: Chronos: Learning the Language of Time Series for a later approach that treats time series as tokens for a language-model-style network.
Check yourself
QuestionWhy does DeepAR divide the lagged value by the scale nu before the LSTM sees it?Show answer
The network's internal non-linearities work well only in a limited range. Dividing by nu_i brings every item's lagged value to a similar size, so the network does not have to learn a different input scale per item. The output is multiplied back by nu_i afterwards.
QuestionCompute the variance of a negative binomial with mean 4 and shape 0.25.Show answer
Variance equals mu plus mu squared times alpha. Here mu squared is 16 and 16 times 0.25 is 4, so the variance is 4 plus 4, which is 8.
QuestionWhy does DeepAR take quantiles of summed sample paths rather than summing the per-step quantiles?Show answer
Each sample path is a joint draw across the horizon, so its sum is a draw from the distribution of the total. The 0.9 quantile of the total is not the sum of per-step 0.9 quantiles, because the steps are correlated. Summing paths keeps the correlation, which is what the paper's coverage analysis checks.
QuestionA forecaster predicts the 0.9 quantile of demand as 50 and the true demand is 60. Using the printed formula with rho = 0.9, is the quantile loss positive or negative, and what is it?Show answer
Positive. The forecast is 50 minus 60, which is minus 10. The forecast is at or below the truth, so the bracket is 0 minus 0.1 times 1, which is minus 0.1. Multiply: 2 times minus 10 times minus 0.1 equals 2. The loss is positive, and the printed formula gives this under-forecast the small weight 1 minus rho.