仓库源文站点原文


title: "Some Evaluations for Time Series Forecasting" categories:


主要以两篇文章为主线, 串讲多个话题. 场景以零售销量预测为例.

<!-- more -->

Metrics for Point Estimations

先来讲 Hyndman and Koehler (2006) Another look at measures of forecast accuracy, 引用数非常高. 这是在沃尔玛于 Kaggle 上组织的比赛 M5 Forecasting: Estimate the unit sales and the uncertainty distribution of Walmart retail goods 上看到的. 比赛分为两个 track, 分别需要预测零售数据的销量和置信区间. 官方给出的 M5 Participants Guide 包含了挺有意思的信息.

Popular Metrics

记时间序列为 $Y_t$, 点估计为 $\hat Y_t$, 误差为 $e_t = Y_t - \hat Y_t$. 历史有 $n$ 个时间点 $Y_1, \dots, Y_n$.

比如 Facebook Prophet 的内置评估用的就是这些.

Scaled Errors

Hyndman and Koehler 推荐的做法是采用 scaled errors. 分母部分相当于相对指标 baseline 取为 random walk, $\hat Yt = Y{t-1}$. 只有当 $Y_t$ 全部相等时, 分母才为零, 而这种情况可以很自然地排除.

以 M5 比赛为例, 记 forecasting horizon 为 $h$, 比如 28 (天), 也就是需要预测未来 28 天的数据. 选用的点估计的 loss 是 Root Mean Squared Scaled Error (RMSSE),

$$ \text{RMSSE} = \sqrt{ \frac{ \frac{1}{h} \sum_{t=n+1}^{n+h} (Y_t - \hat Yt)^2} { \frac{1}{n-1} \sum{t=2}^n (Yt - Y{t-1})^2} }. $$

冠军成绩为 0.52043 (RMSSE 的加权平均), 铜牌线 0.69934, 供参考.

类似地可以定义出其他的 scaled errors.

好处是这是 scale-independent, 即 $Y_t$ 和 $\hat Y_t$ 乘上同一个常数后指标不变, 因此适用于对多个不同 scale 的序列预测的场景.

Evaluating Predictive Count Data Distributions

沃尔玛 M5 比赛的零售数据就是 counts 组成的, 恰好之前我看过不少关于 time series of counts 的文章. 一般而言, 计数时间序列处理的是非负整数 (counts) 且数值较小的时间序列, 若数值很大那么直接近似为连续值即可. 下面讲讲 Kolassa (2016) Evaluating predictive count data distributions in retail sales forecasting.

机器学习界通常更关注点估计, 所谓的 "预测能力", 但是这可能对计数时间序列并不合适. 预测分布可能是更需要的, 统计学界一般更关心这个, 所谓 "推断能力".

For example, quantile forecasts are obviously necessary in supply chain forecasting for setting safety amounts, but also for scenario analyses in promotional or other forecasts.

事实上 M5 就有一个专门的预测分位数的 track, 不过参与度就少很多了.

Count data pose specific challenges for error measures. In particular, minimizing common error measures does not necessarily lead to the "best" forecasting method for count data, especially for intermittent demand series.

Issues on MSE and MAE

众所周知, 期望可以最小化 MSE, 而中位数则可以最小化 MAE. 当数据分布对称时, 用这两个指标还行; 但是对于取值小的计数数列就不一样了.

假设真实分布为 Poisson 分布, intensity rate 为 $\lambda < \log 2 \approx 0.693$, 则中位数为 0, 期望为 $\lambda$. 不论 $\lambda$ 是 0.01 还是 0.5, 0 都令 MAE 最小化. 事实上由于 Poisson 分布的中位数总是整数, 最小化 MAE 会天然地给出整数预测值, 而这通常 biased downward.

Kolassa and Martin (2011) provide a very simple pedagogical illustration of a strictly positive discrete symmetric distribution with an explicit biased E(M)APE-optimal forecast.

Boy-lan and Syntetos (2006) note that "the mean squared error is not suitable for intermittent-demand items because it is sensitive to the occurrence of very high forecast errors".

Predict Quantiles

In store replenishment, retailers need to consider logistical constraints (pack sizes, best by dates, delivery schedules, minimum or maximum truck loads), balancing a lower service level for one product against a higher service level for another. They need to optimize over complex cost functions (time-varying purchasing and sales prices, rebate brackets that kick in once a certain total order amount has been reached), which in turn require flexibility with regard to lead times: we may want to pull orders forward in time, a so-called "forward buy".

上述理由意味着用点估计并不合适. 一个简单的改进是预测各个分位数, 分位数回归用的是 pinball loss. 容易证明, 对应的分位数恰好能使期望 loss 最小 (求导即可, 证明可见 这里 pp. 9-12).

M5 用的是其改版 scaled pinball loss. 给定一个 quantile $u$, 分子是 forecasting horizon 中 pinball loss 的均值, 分母是历史数据 random walk 的 MAE (为了保证 SPL scale-independent). 记 $Q_t(u)$ 为时间 $t$ 时 $u$ 分位数的估计.

$$ \text{SPL}(u) = \frac{ \frac1h \sum_{t=n+1}^{n+h} \left[ u(Y_t - Qt(u)) 1{{Q_t(u)\le Y_t}}

冠军成绩是 0.15420 (对各个分位数平均之后 SPL 的加权平均), 铜牌线为 0.18910, 供参考.

Since M5 does not focus on a particular decision-making problem, neither defines the exact parameters of such a problem (which could also vary for different aggregation levels and series), it becomes evident that all quantiles could be potentially useful. Moreover, since the objective of the M5 is to estimate the uncertainty distribution of the realized values of the examined series as precisely as possible, both sides and both ends of the distribution are considered relevant. In this regard, no special weights are assigned to the examined quantiles, which are therefore equally weighted.

Probabilistic Forecasting

分布估计的评估指标推荐阅读 Czado, C., Gneiting, T., & Held, L. (2009). Predictive model assessment for count data. Biometrics, 65(4), 1254-1261.

提供量化供应链管理服务的 Lokad-knowledge-base) 网站上有很多有意思的话题, 见其 learn 菜单下, knowledge base 栏的 Forecasting, 以及 technology 栏他们自己模型的 发展历史: 从点估计, 到分布估计, 再到深度学习. 传达出的信息大概是: 传统的, 教科书上的方法实际效果差, 深度学习大法好.

Overdispersion in retail sales can result from shoppers independently buying more than one unit of a given product (Ehrenberg, 1959), while zero inflation could well result from items being out-of-stock.

References