度量¶
一些用于比较时间序列的度量。
- darts.metrics.metrics.ae(actual_series, pred_series, intersect=True, *, q=None, time_reduction=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
绝对误差 (AE)。
对于长度为 \(T\) 的真实序列 \(y\) 和预测序列 \(\hat{y}\),它按分量/列、(可选) 分位数和时间步 \(t\) 计算为
\[|y_t - \hat{y}_t|\]如果 \(\hat{y}_t\) 是随机的(包含多个样本)或分位数预测,请使用参数 q 指定计算度量的分位数。默认情况下,它使用中位数 0.5 分位数(对所有样本,或者如果给定,使用分位数预测本身)。
- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
],None
]) – 可选参数,要计算度量的分位数(浮点数 [0, 1])或分位数列表。time_reduction (
Optional
[Callable
[…,ndarray
],None
]) – 可选参数,用于聚合时间轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (c,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于时间轴。如果为 None,则按每个时间步返回度量。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction、component_reduction 和 time_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有时间和分量规约时,数组形状为 (n time steps, n components * n quantiles);在没有时间规约但有分量规约且 len(q) > 1 时,形状为 (n time steps, n quantiles)。适用于
输入参数与上述返回 float 的情况相同,但 len(q) > 1。
单个多变量序列,且至少 component_reduction=None。
单个单变量/多变量序列,且至少 time_reduction=None。
包含 series_reduction 的单变量/多变量序列,且至少有一个 component_reduction=None 或 time_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
- darts.metrics.metrics.ape(actual_series, pred_series, intersect=True, *, q=None, time_reduction=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
绝对百分比误差 (APE)。
对于长度为 \(T\) 的真实序列 \(y\) 和预测序列 \(\hat{y}\),它按分量/列和时间步 \(t\) 计算为百分比值,公式如下:
\[100 \cdot \left| \frac{y_t - \hat{y}_t}{y_t} \right|\]请注意,如果对于某些 \(t\),\(y_t = 0\),则会引发 ValueError。在这种情况下,请考虑使用绝对比例误差 (
ase()
)。如果 \(\hat{y}_t\) 是随机的(包含多个样本)或分位数预测,请使用参数 q 指定计算度量的分位数。默认情况下,它使用中位数 0.5 分位数(对所有样本,或者如果给定,使用分位数预测本身)。
- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
],None
]) – 可选参数,要计算度量的分位数(浮点数 [0, 1])或分位数列表。time_reduction (
Optional
[Callable
[…,ndarray
],None
]) – 可选参数,用于聚合时间轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (c,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于时间轴。如果为 None,则按每个时间步返回度量。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 引发
ValueError – 如果 actual_series 包含零值。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction、component_reduction 和 time_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有时间和分量规约时,数组形状为 (n time steps, n components * n quantiles);在没有时间规约但有分量规约且 len(q) > 1 时,形状为 (n time steps, n quantiles)。适用于
输入参数与上述返回 float 的情况相同,但 len(q) > 1。
单个多变量序列,且至少 component_reduction=None。
单个单变量/多变量序列,且至少 time_reduction=None。
包含 series_reduction 的单变量/多变量序列,且至少有一个 component_reduction=None 或 time_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
- darts.metrics.metrics.arre(actual_series, pred_series, intersect=True, *, q=None, time_reduction=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
绝对范围相对误差 (ARRE)。
对于长度为 \(T\) 的真实序列 \(y\) 和预测序列 \(\hat{y}\),它按分量/列、(可选) 分位数和时间步 \(t\) 计算为百分比值,公式如下:
\[100 \cdot \left| \frac{y_t - \hat{y}_t} {\max_t{y_t} - \min_t{y_t}} \right|\]如果 \(\hat{y}_t\) 是随机的(包含多个样本)或分位数预测,请使用参数 q 指定计算度量的分位数。默认情况下,它使用中位数 0.5 分位数(对所有样本,或者如果给定,使用分位数预测本身)。
- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
],None
]) – 可选参数,要计算度量的分位数(浮点数 [0, 1])或分位数列表。time_reduction (
Optional
[Callable
[…,ndarray
],None
]) – 可选参数,用于聚合时间轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (c,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于时间轴。如果为 None,则按每个时间步返回度量。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 引发
ValueError – 如果 \(\max_t{y_t} = \min_t{y_t}\)。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction、component_reduction 和 time_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有时间和分量规约时,数组形状为 (n time steps, n components * n quantiles);在没有时间规约但有分量规约且 len(q) > 1 时,形状为 (n time steps, n quantiles)。适用于
输入参数与上述返回 float 的情况相同,但 len(q) > 1。
单个多变量序列,且至少 component_reduction=None。
单个单变量/多变量序列,且至少 time_reduction=None。
包含 series_reduction 的单变量/多变量序列,且至少有一个 component_reduction=None 或 time_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
- darts.metrics.metrics.ase(actual_series, pred_series, insample, m=1, intersect=True, *, q=None, time_reduction=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
绝对比例误差 (ASE)(有关比例预测误差的更多信息,请参阅 [1])。
它是通过朴素 m 季节性预测的平均绝对误差 (MAE) 进行缩放的绝对误差 (AE)。
对于长度为 \(T\) 的真实序列 \(y\) 和预测序列 \(\hat{y}\),它按分量/列、(可选) 分位数和时间步 \(t\) 计算为
\[\frac{AE(y_{t_p+1:t_p+T}, \hat{y}_{t_p+1:t_p+T})}{E_m},\]其中 \(t_p\) 是预测时间(第一个预测点前一步),\(AE\) 是绝对误差 (
ae()
),\(E_m\) 是朴素 m 季节性预测在 insample 序列 \(y_{0:t_p}\)(在 \(t_p\) 结束的真实序列)上的平均绝对误差 (MAE)\[E_m = MAE(y_{m:t_p}, y_{0:t_p - m}).\]如果 \(\hat{y}_t\) 是随机的(包含多个样本)或分位数预测,请使用参数 q 指定计算度量的分位数。默认情况下,它使用中位数 0.5 分位数(对所有样本,或者如果给定,使用分位数预测本身)。
- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。insample (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 用于预测 pred_series 的训练序列。该序列用于计算朴素预测器在训练数据上获得的误差规模。m (
int
) – 用于计算误差规模 \(E_m\) 的差分季节性(如度量描述中所述)。\(m=1\) 对应于非季节性 \(E_m\)(例如朴素地重复最后一个观测值),而 \(m>1\) 对应于季节性 \(E_m\)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
],None
]) – 可选参数,要计算度量的分位数(浮点数 [0, 1])或分位数列表。time_reduction (
Optional
[Callable
[…,ndarray
],None
]) – 可选参数,用于聚合时间轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (c,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于时间轴。如果为 None,则按每个时间步返回度量。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 引发
ValueError – 如果 insample 序列是周期性的( \(y_t = y_{t-m}\) ),或者 insample 中的任何序列没有在 pred_series 中对应预测的开始前一个时间步结束。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction、component_reduction 和 time_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有时间和分量规约时,数组形状为 (n time steps, n components * n quantiles);在没有时间规约但有分量规约且 len(q) > 1 时,形状为 (n time steps, n quantiles)。适用于
输入参数与上述返回 float 的情况相同,但 len(q) > 1。
单个多变量序列,且至少 component_reduction=None。
单个单变量/多变量序列,且至少 time_reduction=None。
包含 series_reduction 的单变量/多变量序列,且至少有一个 component_reduction=None 或 time_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
参考资料
- darts.metrics.metrics.coefficient_of_variation(actual_series, pred_series, intersect=True, *, q=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
变异系数(百分比)。
对于长度为 \(T\) 的真实序列 \(y\) 和预测序列 \(\hat{y}\),它按分量/列和(可选)分位数计算为百分比值,公式如下:
\[100 \cdot \text{RMSE}(y_t, \hat{y}_t) / \bar{y},\]其中 \(RMSE\) 是均方根误差 (
rmse()
),\(\bar{y}\) 是 \(y\) 在所有时间步上的平均值。如果 \(\hat{y}_t\) 是随机的(包含多个样本)或分位数预测,请使用参数 q 指定计算度量的分位数。默认情况下,它使用中位数 0.5 分位数(对所有样本,或者如果给定,使用分位数预测本身)。
- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
],None
]) – 可选参数,要计算度量的分位数(浮点数 [0, 1])或分位数列表。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction 和 component_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有分量规约时,数组形状为 (n components * n quantiles,);在有分量规约且 len(q) > 1 时,形状为 (n quantiles,)。适用于
输入参数与上述返回 float 的情况相同,但 len(q) > 1。
单个多变量序列,且至少 component_reduction=None。
包含 series_reduction 的单变量/多变量序列,且 component_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
- darts.metrics.metrics.dtw_metric(actual_series, pred_series, metric=<function mae>, *, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False, **kwargs)[source]¶
在将 actual_series 和 pred_series 传递给度量之前,应用动态时间规整。支持比较不同长度、相位和时间索引的序列。
默认使用
mae()
作为度量。有关更多支持的参数,请参阅
dtw()
。- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。metric (
Callable
[[Union
[TimeSeries
,Sequence
[TimeSeries
]],Union
[TimeSeries
,Sequence
[TimeSeries
]]],Union
[float
,list
[float
],ndarray
,list
[ndarray
]]]) – 要使用的选定度量函数,其签名为 ‘[[TimeSeries, TimeSeries], float]’。默认为 mae。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction 和 component_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有分量规约时,数组形状为 (n components * n quantiles,);在有分量规约且 len(q) > 1 时,形状为 (n quantiles,)。适用于
输入参数与上述返回 float 的情况相同,但 len(q) > 1。
单个多变量序列,且至少 component_reduction=None。
包含 series_reduction 的单变量/多变量序列,且 component_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
- darts.metrics.metrics.err(actual_series, pred_series, intersect=True, *, q=None, time_reduction=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
误差 (ERR)。
对于长度为 \(T\) 的真实序列 \(y\) 和预测序列 \(\hat{y}\),它按分量/列、(可选) 分位数和时间步 \(t\) 计算为
\[y_t - \hat{y}_t\]如果 \(\hat{y}_t\) 是随机的(包含多个样本)或分位数预测,请使用参数 q 指定计算度量的分位数。默认情况下,它使用中位数 0.5 分位数(对所有样本,或者如果给定,使用分位数预测本身)。
- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
],None
]) – 可选参数,要计算度量的分位数(浮点数 [0, 1])或分位数列表。time_reduction (
Optional
[Callable
[…,ndarray
],None
]) – 可选参数,用于聚合时间轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (c,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于时间轴。如果为 None,则按每个时间步返回度量。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction、component_reduction 和 time_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有时间和分量规约时,数组形状为 (n time steps, n components * n quantiles);在没有时间规约但有分量规约且 len(q) > 1 时,形状为 (n time steps, n quantiles)。适用于
输入参数与上述返回 float 的情况相同,但 len(q) > 1。
单个多变量序列,且至少 component_reduction=None。
单个单变量/多变量序列,且至少 time_reduction=None。
包含 series_reduction 的单变量/多变量序列,且至少有一个 component_reduction=None 或 time_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
- darts.metrics.metrics.ic(actual_series, pred_series, intersect=True, *, q_interval=None, q=None, time_reduction=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
区间覆盖率 (IC)。
如果观测值在区间内,IC 返回 1;否则返回 0。
对于长度为 \(T\) 的真实序列 \(y\) 和预测的随机或分位数序列 \(\hat{y}\),它按分量/列、分位数区间 \((q_l,q_h)\) 和时间步 \(t\) 计算为
\[\begin{split}\begin{equation} \begin{cases} 1 & \text{if } L_t < y_t < U_t \\ 0 & \text{otherwise} \end{cases} \end{equation}\end{split}\]其中 \(U_t\) 是时间 \(t\) 时预测的上界分位数 \(\hat{y}_{q_h,t}\)(所有预测的分位数或样本),\(L_t\) 是预测的下界分位数 \(\hat{y}_{q_l,t}\)。
- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q_interval (
Union
[tuple
[float
,float
],Sequence
[tuple
[float
,float
]],None
]) – 用于计算度量的分位数区间。必须是包含元素(低分位数,高分位数)的元组(单个区间)或元组序列(多个区间)。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
],None
]) – 此度量不支持分位数 q;请改用 q_interval。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。time_reduction (
Optional
[Callable
[…,ndarray
],None
]) – 可选参数,用于聚合时间轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (c,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于时间轴。如果为 None,则按每个时间步返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q_interval) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction、component_reduction 和 time_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有时间和分量规约时,数组形状为 (n time steps, n components * n q intervals);在没有时间规约但有分量规约且 len(q_interval) > 1 时,形状为 (n time steps, n q intervals)。适用于
输入与上述返回 float 的情况相同,但 len(q_interval) > 1。
单个多变量序列,且至少 component_reduction=None。
单个单变量/多变量序列,且至少 time_reduction=None。
包含 series_reduction 的单变量/多变量序列,且至少有一个 component_reduction=None 或 time_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
- darts.metrics.metrics.incs_qr(actual_series, pred_series, intersect=True, *, q_interval=None, symmetric=True, q=None, time_reduction=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
分位数回归的区间非一致性分数 (INCS_QR)。
当观测值在区间之外时,INCS_QR 提供到最近预测分位数区间边界的绝对误差。否则,它提供到更近边界的负绝对误差。
对于长度为 \(T\) 的真实序列 \(y\) 和预测的随机或分位数序列 \(\hat{y}\),它按分量/列、分位数区间 \((q_l,q_h)\) 和时间步 \(t\) 计算为
\[\max(L_t - y_t, y_t - U_t)\]其中 \(U_t\) 是时间 \(t\) 时预测的上界分位数 \(\hat{y}_{q_h,t}\)(所有预测的分位数或样本),\(L_t\) 是预测的下界分位数 \(\hat{y}_{q_l,t}\)。
- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q_interval (
Union
[tuple
[float
,float
],Sequence
[tuple
[float
,float
]],None
]) – 用于计算度量的分位数区间。必须是包含元素(低分位数,高分位数)的元组(单个区间)或元组序列(多个区间)。symmetric (
bool
) – 是否返回对称的非一致性分数。如果为 False,则返回非对称分数(下界和上界分位数区间边界的单独分数;在分量轴中返回)。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
],None
]) – 此度量不支持分位数 q;请改用 q_interval。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。time_reduction (
Optional
[Callable
[…,ndarray
],None
]) – 可选参数,用于聚合时间轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (c,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于时间轴。如果为 None,则按每个时间步返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q_interval) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction、component_reduction 和 time_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有时间和分量规约时,数组形状为 (n time steps, n components * n q intervals);在没有时间规约但有分量规约且 len(q_interval) > 1 时,形状为 (n time steps, n q intervals)。适用于
输入与上述返回 float 的情况相同,但 len(q_interval) > 1。
单个多变量序列,且至少 component_reduction=None。
单个单变量/多变量序列,且至少 time_reduction=None。
包含 series_reduction 的单变量/多变量序列,且至少有一个 component_reduction=None 或 time_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
- darts.metrics.metrics.interval_support(func)[source]¶
此装饰器添加了对分位数区间度量的支持,包括健全性检查、处理以及从区间中提取分位数。
- 返回类型
Callable
[…,Union
[float
,list
[float
],ndarray
,list
[ndarray
]]]
- darts.metrics.metrics.iw(actual_series, pred_series, intersect=True, *, q_interval=None, q=None, time_reduction=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
区间宽度 (IW)。
IW 提供预测分位数区间的宽度/长度。
对于长度为 \(T\) 的真实序列 \(y\) 和预测的随机或分位数序列 \(\hat{y}\),它按分量/列、分位数区间 \((q_l,q_h)\) 和时间步 \(t\) 计算为
\[U_t - L_t,\]其中 \(U_t\) 是时间 \(t\) 时预测的上界分位数 \(\hat{y}_{q_h,t}\)(所有预测的分位数或样本),\(L_t\) 是预测的下界分位数 \(\hat{y}_{q_l,t}\)。
- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q_interval (
Union
[tuple
[float
,float
],Sequence
[tuple
[float
,float
]],None
]) – 用于计算度量的分位数区间。必须是包含元素(低分位数,高分位数)的元组(单个区间)或元组序列(多个区间)。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
],None
]) – 此度量不支持分位数 q;请改用 q_interval。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。time_reduction (
Optional
[Callable
[…,ndarray
],None
]) – 可选参数,用于聚合时间轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (c,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于时间轴。如果为 None,则按每个时间步返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q_interval) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction、component_reduction 和 time_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有时间和分量规约时,数组形状为 (n time steps, n components * n q intervals);在没有时间规约但有分量规约且 len(q_interval) > 1 时,形状为 (n time steps, n q intervals)。适用于
输入与上述返回 float 的情况相同,但 len(q_interval) > 1。
单个多变量序列,且至少 component_reduction=None。
单个单变量/多变量序列,且至少 time_reduction=None。
包含 series_reduction 的单变量/多变量序列,且至少有一个 component_reduction=None 或 time_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
- darts.metrics.metrics.iws(actual_series, pred_series, intersect=True, *, q_interval=None, q=None, time_reduction=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
区间 Winkler 分数 (IWS) [1]。
如果观测值在区间之外,IWS 提供分位数区间的长度/宽度以及一个惩罚。
对于长度为 \(T\) 的真实序列 \(y\) 和预测的随机或分位数序列 \(\hat{y}\),它按分量/列、分位数区间 \((q_l,q_h)\) 和时间步 \(t\) 计算为
\[\begin{split}\begin{equation} \begin{cases} (U_t - L_t) + \frac{1}{q_l} (L_t - y_t) & \text{if } y_t < L_t \\ (U_t - L_t) & \text{if } L_t \leq y_t \leq U_t \\ (U_t - L_t) + \frac{1}{1 - q_h} (y_t - U_t) & \text{if } y_t > U_t \end{cases} \end{equation}\end{split}\]其中 \(U_t\) 是时间 \(t\) 时预测的上界分位数 \(\hat{y}_{q_h,t}\)(所有预测的分位数或样本),\(L_t\) 是预测的下界分位数 \(\hat{y}_{q_l,t}\)。
- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q_interval (
Union
[tuple
[float
,float
],Sequence
[tuple
[float
,float
]],None
]) – 用于计算度量的分位数区间。必须是包含元素(低分位数,高分位数)的元组(单个区间)或元组序列(多个区间)。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
],None
]) – 此度量不支持分位数 q;请改用 q_interval。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。time_reduction (
Optional
[Callable
[…,ndarray
],None
]) – 可选参数,用于聚合时间轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (c,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于时间轴。如果为 None,则按每个时间步返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q_interval) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction、component_reduction 和 time_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有时间和分量规约时,数组形状为 (n time steps, n components * n q intervals);在没有时间规约但有分量规约且 len(q_interval) > 1 时,形状为 (n time steps, n q intervals)。适用于
输入与上述返回 float 的情况相同,但 len(q_interval) > 1。
单个多变量序列,且至少 component_reduction=None。
单个单变量/多变量序列,且至少 time_reduction=None。
包含 series_reduction 的单变量/多变量序列,且至少有一个 component_reduction=None 或 time_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
参考资料
- darts.metrics.metrics.mae(actual_series, pred_series, intersect=True, *, q=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
平均绝对误差 (MAE)。
对于长度为 \(T\) 的真实序列 \(y\) 和预测序列 \(\hat{y}\),它按分量/列和(可选)分位数计算为
\[\frac{1}{T}\sum_{t=1}^T{|y_t - \hat{y}_t|}\]如果 \(\hat{y}_t\) 是随机的(包含多个样本)或分位数预测,请使用参数 q 指定计算度量的分位数。默认情况下,它使用中位数 0.5 分位数(对所有样本,或者如果给定,使用分位数预测本身)。
- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
],None
]) – 可选参数,要计算度量的分位数(浮点数 [0, 1])或分位数列表。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction 和 component_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有分量规约时,数组形状为 (n components * n quantiles,);在有分量规约且 len(q) > 1 时,形状为 (n quantiles,)。适用于
输入参数与上述返回 float 的情况相同,但 len(q) > 1。
单个多变量序列,且至少 component_reduction=None。
包含 series_reduction 的单变量/多变量序列,且 component_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
- darts.metrics.metrics.mape(actual_series, pred_series, intersect=True, *, q=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
平均绝对百分比误差 (MAPE)。
对于长度为 \(T\) 的真实序列 \(y\) 和预测序列 \(\hat{y}\),它按分量/列和(可选)分位数计算为百分比值,公式如下:
\[100 \cdot \frac{1}{T} \sum_{t=1}^{T}{\left| \frac{y_t - \hat{y}_t}{y_t} \right|}\]请注意,如果对于某些 \(t\),\(y_t = 0\),则会引发 ValueError。在这种情况下,请考虑使用平均绝对比例误差 (
mase()
)。如果 \(\hat{y}_t\) 是随机的(包含多个样本)或分位数预测,请使用参数 q 指定计算度量的分位数。默认情况下,它使用中位数 0.5 分位数(对所有样本,或者如果给定,使用分位数预测本身)。
- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
],None
]) – 可选参数,要计算度量的分位数(浮点数 [0, 1])或分位数列表。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 引发
ValueError – 如果 actual_series 包含零值。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction 和 component_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有分量规约时,数组形状为 (n components * n quantiles,);在有分量规约且 len(q) > 1 时,形状为 (n quantiles,)。适用于
输入参数与上述返回 float 的情况相同,但 len(q) > 1。
单个多变量序列,且至少 component_reduction=None。
包含 series_reduction 的单变量/多变量序列,且 component_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
- darts.metrics.metrics.marre(actual_series, pred_series, intersect=True, *, q=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
平均绝对范围相对误差 (MARRE)。
对于长度为 \(T\) 的真实序列 \(y\) 和预测序列 \(\hat{y}\),它按分量/列和(可选)分位数计算为百分比值,公式如下:
\[100 \cdot \frac{1}{T} \sum_{t=1}^{T} {\left| \frac{y_t - \hat{y}_t} {\max_t{y_t} - \min_t{y_t}} \right|}\]如果 \(\hat{y}_t\) 是随机的(包含多个样本)或分位数预测,请使用参数 q 指定计算度量的分位数。默认情况下,它使用中位数 0.5 分位数(对所有样本,或者如果给定,使用分位数预测本身)。
- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
],None
]) – 可选参数,要计算度量的分位数(浮点数 [0, 1])或分位数列表。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 引发
ValueError – 如果 \(\max_t{y_t} = \min_t{y_t}\)。
float –
单一度量分数,适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction 和 component_reduction 的单变量/多变量序列(列表)。
np.ndarray –
一个 numpy 数组,包含度量分数。在没有分量规约时,数组形状为 (n components,)。适用于
单个多变量序列,且至少 component_reduction=None。
包含 series_reduction 且 component_reduction=None 的单变量/多变量序列。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]
- darts.metrics.metrics.mase(actual_series, pred_series, insample, m=1, intersect=True, *, q=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
平均绝对比例误差 (MASE)(有关比例预测误差的更多信息,请参阅 [1])。
它是通过朴素 m 季节性预测的平均绝对误差 (MAE) 进行缩放的平均绝对误差 (MAE)。
对于长度为 \(T\) 的真实序列 \(y\) 和预测序列 \(\hat{y}\),它按分量/列和(可选)分位数计算为
\[\frac{MAE(y_{t_p+1:t_p+T}, \hat{y}_{t_p+1:t_p+T})}{E_m},\]其中 \(t_p\) 是预测时间(第一个预测点前一步),\(MAE\) 是平均绝对误差 (
mae()
),\(E_m\) 是朴素 m 季节性预测在 insample 序列 \(y_{0:t_p}\)(在 \(t_p\) 结束的真实序列)上的 MAE\[E_m = MAE(y_{m:t_p}, y_{0:t_p - m}).\]如果 \(\hat{y}_t\) 是随机的(包含多个样本)或分位数预测,请使用参数 q 指定计算度量的分位数。默认情况下,它使用中位数 0.5 分位数(对所有样本,或者如果给定,使用分位数预测本身)。
- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。insample (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 用于预测 pred_series 的训练序列。该序列用于计算朴素预测器在训练数据上获得的误差规模。m (
int
) – 用于计算误差规模 \(E_m\) 的差分季节性(如度量描述中所述)。\(m=1\) 对应于非季节性 \(E_m\)(例如朴素地重复最后一个观测值),而 \(m>1\) 对应于季节性 \(E_m\)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
],None
]) – 可选参数,要计算度量的分位数(浮点数 [0, 1])或分位数列表。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 引发
ValueError – 如果 insample 序列是周期性的( \(y_t = y_{t-m}\) ),或者 insample 中的任何序列没有在 pred_series 中对应预测的开始前一个时间步结束。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction 和 component_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有分量规约时,数组形状为 (n components * n quantiles,);在有分量规约且 len(q) > 1 时,形状为 (n quantiles,)。适用于
输入参数与上述返回 float 的情况相同,但 len(q) > 1。
单个多变量序列,且至少 component_reduction=None。
包含 series_reduction 的单变量/多变量序列,且 component_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
参考资料
- darts.metrics.metrics.merr(actual_series, pred_series, intersect=True, *, q=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
平均误差 (MERR)。
对于长度为 \(T\) 的真实序列 \(y\) 和预测序列 \(\hat{y}\),它按分量/列和(可选)分位数计算为
\[\frac{1}{T}\sum_{t=1}^T{(y_t - \hat{y}_t)}\]如果 \(\hat{y}_t\) 是随机的(包含多个样本)或分位数预测,请使用参数 q 指定计算度量的分位数。默认情况下,它使用中位数 0.5 分位数(对所有样本,或者如果给定,使用分位数预测本身)。
- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
],None
]) – 可选参数,要计算度量的分位数(浮点数 [0, 1])或分位数列表。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction 和 component_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有分量规约时,数组形状为 (n components * n quantiles,);在有分量规约且 len(q) > 1 时,形状为 (n quantiles,)。适用于
输入参数与上述返回 float 的情况相同,但 len(q) > 1。
单个多变量序列,且至少 component_reduction=None。
包含 series_reduction 的单变量/多变量序列,且 component_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
- darts.metrics.metrics.mic(actual_series, pred_series, intersect=True, *, q_interval=None, q=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
平均区间覆盖率 (MIC)。
MIC 提供时间聚合的区间覆盖率
ic()
- 观测值落在区间内的比例。对于长度为 \(T\) 的真实序列 \(y\) 和预测的随机或分位数序列 \(\hat{y}\),它按分量/列、分位数区间 \((q_l,q_h)\) 和时间步 \(t\) 计算为
\[\frac{1}{T}\sum_{t=1}^T{C(y_t, \hat{y}_{t}, q_h, q_l)},\]其中 \(C\) 是区间覆盖率
ic()
。- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q_interval (
Union
[tuple
[float
,float
],Sequence
[tuple
[float
,float
]],None
]) – 用于计算度量的分位数区间。必须是包含元素(低分位数,高分位数)的元组(单个区间)或元组序列(多个区间)。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
],None
]) – 此度量不支持分位数 q;请改用 q_interval。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q_interval) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction 和 component_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有分量规约时,数组形状为 (n components * n q intervals,);在有分量规约且 len(q_interval) > 1 时,形状为 (n q intervals,)。适用于
输入与上述返回 float 的情况相同,但 len(q_interval) > 1。
单个多变量序列,且至少 component_reduction=None。
包含 series_reduction 的单变量/多变量序列,且 component_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
- darts.metrics.metrics.mincs_qr(actual_series, pred_series, intersect=True, *, q_interval=None, symmetric=True, q=None, time_reduction=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
分位数回归的平均区间非一致性分数 (MINCS_QR)。
MINCS_QR 提供时间聚合的 INCS_QR
incs_qr()
。对于长度为 \(T\) 的真实序列 \(y\) 和预测的随机或分位数序列 \(\hat{y}\),它按分量/列、分位数区间 \((q_l,q_h)\) 和时间步 \(t\) 计算为
\[\frac{1}{T}\sum_{t=1}^T{INCS_QR(y_t, \hat{y}_{t}, q_h, q_l)},\]其中 \(INCS_QR\) 是分位数回归的区间非一致性分数
incs_qr()
。- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q_interval (
Union
[tuple
[float
,float
],Sequence
[tuple
[float
,float
]],None
]) – 用于计算度量的分位数区间。必须是包含元素(低分位数,高分位数)的元组(单个区间)或元组序列(多个区间)。symmetric (
bool
) – 是否返回对称的非一致性分数。如果为 False,则返回非对称分数(下界和上界分位数区间边界的单独分数;在分量轴中返回)。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
],None
]) – 此度量不支持分位数 q;请改用 q_interval。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q_interval) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction 和 component_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有分量规约时,数组形状为 (n components * n q intervals,);在有分量规约且 len(q_interval) > 1 时,形状为 (n q intervals,)。适用于
输入与上述返回 float 的情况相同,但 len(q_interval) > 1。
单个多变量序列,且至少 component_reduction=None。
包含 series_reduction 的单变量/多变量序列,且 component_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
- darts.metrics.metrics.miw(actual_series, pred_series, intersect=True, *, q_interval=None, q=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
平均区间宽度 (MIW)。
MIW 提供预测分位数区间的时间聚合宽度/长度。
对于长度为 \(T\) 的真实序列 \(y\) 和预测的随机或分位数序列 \(\hat{y}\),它按分量/列、分位数区间 \((q_l,q_h)\) 和时间步 \(t\) 计算为
\[\frac{1}{T}\sum_{t=1}^T{U_t - L_t},\]其中 \(U_t\) 是时间 \(t\) 时预测的上界分位数 \(\hat{y}_{q_h,t}\)(所有预测的分位数或样本),\(L_t\) 是预测的下界分位数 \(\hat{y}_{q_l,t}\)。
- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q_interval (
Union
[tuple
[float
,float
],Sequence
[tuple
[float
,float
]],None
]) – 用于计算度量的分位数区间。必须是包含元素(低分位数,高分位数)的元组(单个区间)或元组序列(多个区间)。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
],None
]) – 此度量不支持分位数 q;请改用 q_interval。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q_interval) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction 和 component_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有分量规约时,数组形状为 (n components * n q intervals,);在有分量规约且 len(q_interval) > 1 时,形状为 (n q intervals,)。适用于
输入与上述返回 float 的情况相同,但 len(q_interval) > 1。
单个多变量序列,且至少 component_reduction=None。
包含 series_reduction 的单变量/多变量序列,且 component_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
- darts.metrics.metrics.miws(actual_series, pred_series, intersect=True, *, q_interval=None, q=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
平均区间 Winkler 分数 (IWS) [1]。
如果观测值在区间之外,MIWS 提供分位数区间的时间聚合长度/宽度以及一个惩罚。
对于长度为 \(T\) 的真实序列 \(y\) 和预测的随机或分位数序列 \(\hat{y}\),它按分量/列、分位数区间 \((q_l,q_h)\) 和时间步 \(t\) 计算为
\[\frac{1}{T}\sum_{t=1}^T{W_t(y_t, \hat{y}_{t}, q_h, q_l)},\]其中 \(W\) 是 Winkler 分数
iws()
。- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q_interval (
Union
[tuple
[float
,float
],Sequence
[tuple
[float
,float
]],None
]) – 用于计算度量的分位数区间。必须是包含元素(低分位数,高分位数)的元组(单个区间)或元组序列(多个区间)。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
],None
]) – 此度量不支持分位数 q;请改用 q_interval。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q_interval) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction 和 component_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有分量规约时,数组形状为 (n components * n q intervals,);在有分量规约且 len(q_interval) > 1 时,形状为 (n q intervals,)。适用于
输入与上述返回 float 的情况相同,但 len(q_interval) > 1。
单个多变量序列,且至少 component_reduction=None。
包含 series_reduction 的单变量/多变量序列,且 component_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
参考资料
- darts.metrics.metrics.mql(actual_series, pred_series, intersect=True, *, q=0.5, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
平均分位数损失 (MQL)。
也称为 Pinball Loss。QL 是一个度量,用于量化预测的确定性分位数或包含 N 个样本的随机/概率 pred_series 的值分布中特定分位数 \(q\) 的准确性。
MQL 首先计算所有样本值的特定分位数以及每个时间步的损失,然后计算时间轴上的平均值。
对于真实序列 \(y\) 和预测的形状为 \(T \times N\) 的随机/概率序列(包含 N 个样本) \(\hat{y}\),它按列/分量和分位数计算为
\[2 \frac{1}{T}\sum_{t=1}^T{\max((q - 1) (y_t - \hat{y}_{t,q}), q (y_t - \hat{y}_{t,q}))},\]其中 \(\hat{y}_{t,q}\) 是时间 \(t\) 时分位数 \(q\)(所有预测的分位数或样本)的值。因子 2 使损失更具可解释性,因为当 q=0.5 时,损失与平均绝对误差 (
mae()
) 相同。- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
]]) – 要计算度量的分位数(浮点数 [0, 1])或分位数列表。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction 和 component_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有分量规约时,数组形状为 (n components * n quantiles,);在有分量规约且 len(q) > 1 时,形状为 (n quantiles,)。适用于
输入参数与上述返回 float 的情况相同,但 len(q) > 1。
单个多变量序列,且至少 component_reduction=None。
包含 series_reduction 的单变量/多变量序列,且 component_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
- darts.metrics.metrics.mse(actual_series, pred_series, intersect=True, *, q=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
均方误差 (MSE)。
对于长度为 \(T\) 的真实序列 \(y\) 和预测序列 \(\hat{y}\),它按分量/列和(可选)分位数计算为
\[\frac{1}{T}\sum_{t=1}^T{(y_t - \hat{y}_t)^2}.\]如果 \(\hat{y}_t\) 是随机的(包含多个样本)或分位数预测,请使用参数 q 指定计算度量的分位数。默认情况下,它使用中位数 0.5 分位数(对所有样本,或者如果给定,使用分位数预测本身)。
- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
],None
]) – 可选参数,要计算度量的分位数(浮点数 [0, 1])或分位数列表。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction 和 component_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有分量规约时,数组形状为 (n components * n quantiles,);在有分量规约且 len(q) > 1 时,形状为 (n quantiles,)。适用于
输入参数与上述返回 float 的情况相同,但 len(q) > 1。
单个多变量序列,且至少 component_reduction=None。
包含 series_reduction 的单变量/多变量序列,且 component_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
- darts.metrics.metrics.msse(actual_series, pred_series, insample, m=1, intersect=True, *, q=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
均方比例误差 (MSSE)(有关比例预测误差的更多信息,请参阅 [1])。
它是通过朴素 m 季节性预测的均方误差 (MSE) 进行缩放的均方误差 (MSE)。
对于长度为 \(T\) 的真实序列 \(y\) 和预测序列 \(\hat{y}\),它按分量/列和(可选)分位数计算为
\[\frac{MSE(y_{t_p+1:t_p+T}, \hat{y}_{t_p+1:t_p+T})}{E_m},\]其中 \(t_p\) 是预测时间(第一个预测点前一步),\(MSE\) 是均方误差 (
mse()
),\(E_m\) 是朴素 m 季节性预测在 insample 序列 \(y_{0:t_p}\)(在 \(t_p\) 结束的真实序列)上的 MSE\[E_m = MSE(y_{m:t_p}, y_{0:t_p - m}).\]如果 \(\hat{y}_t\) 是随机的(包含多个样本)或分位数预测,请使用参数 q 指定计算度量的分位数。默认情况下,它使用中位数 0.5 分位数(对所有样本,或者如果给定,使用分位数预测本身)。
- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。insample (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 用于预测 pred_series 的训练序列。该序列用于计算朴素预测器在训练数据上获得的误差规模。m (
int
) – 用于计算误差规模 \(E_m\) 的差分季节性(如度量描述中所述)。\(m=1\) 对应于非季节性 \(E_m\)(例如朴素地重复最后一个观测值),而 \(m>1\) 对应于季节性 \(E_m\)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
],None
]) – 可选参数,要计算度量的分位数(浮点数 [0, 1])或分位数列表。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 引发
ValueError – 如果 insample 序列是周期性的( \(y_t = y_{t-m}\) ),或者 insample 中的任何序列没有在 pred_series 中对应预测的开始前一个时间步结束。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction 和 component_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有分量规约时,数组形状为 (n components * n quantiles,);在有分量规约且 len(q) > 1 时,形状为 (n quantiles,)。适用于
输入参数与上述返回 float 的情况相同,但 len(q) > 1。
单个多变量序列,且至少 component_reduction=None。
包含 series_reduction 的单变量/多变量序列,且 component_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
参考资料
- darts.metrics.metrics.multi_ts_support(func)[source]¶
此装饰器进一步调整了接受两个(或三个,对于带有 insample 的比例度量)单变量/多变量
TimeSeries
实例作为输入的度量函数,添加了对等长TimeSeries
序列的支持。该装饰器计算具有相同索引的TimeSeries
的成对度量,并返回一个浮点值,该值是使用作为参数传递给度量函数的 series_reduction 子例程计算所有成对度量的函数得出的。如果输入为 ‘Sequence[TimeSeries]’,此装饰器还提供针对不同
TimeSeries
的度量评估并行化支持(如果 n_jobs 参数未设置为 1)。- 返回类型
Callable
[…,Union
[float
,list
[float
],ndarray
,list
[ndarray
]]]
- darts.metrics.metrics.multivariate_support(func)[source]¶
此装饰器将一个接受两个单变量 TimeSeries 实例作为输入的度量函数转换为一个接受两个等长多变量 TimeSeries 实例的函数,计算具有相同索引的分量的成对单变量度量,并返回一个浮点值,该值是使用作为参数传递给度量函数的 component_reduction 子例程计算所有单变量度量的函数得出的。
- 返回类型
Callable
[…,Union
[float
,list
[float
],ndarray
,list
[ndarray
]]]
- darts.metrics.metrics.ope(actual_series, pred_series, intersect=True, *, q=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
整体百分比误差 (OPE)。
对于长度为 \(T\) 的真实序列 \(y\) 和预测序列 \(\hat{y}\),它按分量/列和(可选)分位数计算为百分比值,公式如下:
\[100 \cdot \left| \frac{\sum_{t=1}^{T}{y_t} - \sum_{t=1}^{T}{\hat{y}_t}}{\sum_{t=1}^{T}{y_t}} \right|.\]如果 \(\hat{y}_t\) 是随机的(包含多个样本)或分位数预测,请使用参数 q 指定计算度量的分位数。默认情况下,它使用中位数 0.5 分位数(对所有样本,或者如果给定,使用分位数预测本身)。
- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
],None
]) – 可选参数,要计算度量的分位数(浮点数 [0, 1])或分位数列表。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 引发
ValueError – 如果 \(\sum_{t=1}^{T}{y_t} = 0\)。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction 和 component_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有分量规约时,数组形状为 (n components * n quantiles,);在有分量规约且 len(q) > 1 时,形状为 (n quantiles,)。适用于
输入参数与上述返回 float 的情况相同,但 len(q) > 1。
单个多变量序列,且至少 component_reduction=None。
包含 series_reduction 的单变量/多变量序列,且 component_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
- darts.metrics.metrics.ql(actual_series, pred_series, intersect=True, *, q=0.5, time_reduction=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
分位数损失 (QL)。
也称为 Pinball Loss。QL 是一个度量,用于量化预测的确定性分位数或包含 N 个样本的随机/概率 pred_series 的值分布中特定分位数 \(q\) 的准确性。
QL 计算所有样本值的特定分位数以及每个时间步的损失。
对于真实序列 \(y\) 和预测的形状为 \(T \times N\) 的随机/概率序列(包含 N 个样本) \(\hat{y}\),它按列/分量、分位数和时间步 \(t\) 计算为
\[2 \max((q - 1) (y_t - \hat{y}_{t,q}), q (y_t - \hat{y}_{t,q})),\]其中 \(\hat{y}_{t,q}\) 是时间 \(t\) 时分位数 \(q\)(所有预测的分位数或样本)的值。因子 2 使损失更具可解释性,因为当 q=0.5 时,损失与绝对误差 (
ae()
) 相同。- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
]]) – 要计算度量的分位数(浮点数 [0, 1])或分位数列表。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。time_reduction (
Optional
[Callable
[…,ndarray
],None
]) – 可选参数,用于聚合时间轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (c,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于时间轴。如果为 None,则按每个时间步返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction、component_reduction 和 time_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有时间和分量规约时,数组形状为 (n time steps, n components * n quantiles);在没有时间规约但有分量规约且 len(q) > 1 时,形状为 (n time steps, n quantiles)。适用于
输入参数与上述返回 float 的情况相同,但 len(q) > 1。
单个多变量序列,且至少 component_reduction=None。
单个单变量/多变量序列,且至少 time_reduction=None。
包含 series_reduction 的单变量/多变量序列,且至少有一个 component_reduction=None 或 time_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
- darts.metrics.metrics.qr(actual_series, pred_series, intersect=True, *, q=0.5, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
分位数风险 (QR)
QR 是一个度量,用于量化包含 N 个样本的随机/概率 pred_series 预测值分布中特定分位数 \(q\) 的准确性。
与分位数损失 (QL) 的主要区别在于,QR 在沿时间轴求和的所有样本值的总和上计算分位数和损失(QL 计算每个时间步的分位数和损失)。
对于真实序列 \(y\) 和预测的形状为 \(T \times N\) 的随机/概率序列(包含 N 个样本) \(\hat{y}\),它按列/分量和分位数计算为
\[2 \frac{QL(Z, \hat{Z}_q)}{Z},\]其中 \(QL\) 是分位数损失 (
ql()
),\(Z = \sum_{t=1}^{T} y_t\) 是所有目标/真实值的总和,\(\hat{Z} = \sum_{t=1}^{T} \hat{y}_t\) 是沿时间轴所有预测样本的总和,\(\hat{Z}_q\) 是该总和的分位数 \(q\)。- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
]]) – 要计算度量的分位数(浮点数 [0, 1])或分位数列表。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction 和 component_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有分量规约时,数组形状为 (n components * n quantiles,);在有分量规约且 len(q) > 1 时,形状为 (n quantiles,)。适用于
输入参数与上述返回 float 的情况相同,但 len(q) > 1。
单个多变量序列,且至少 component_reduction=None。
包含 series_reduction 的单变量/多变量序列,且 component_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
- darts.metrics.metrics.r2_score(actual_series, pred_series, intersect=True, *, q=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
决定系数 \(R^2\)(更多详细信息请参阅 [1])。
对于长度为 \(T\) 的真实序列 \(y\) 和预测序列 \(\hat{y}\),它按分量/列和(可选)分位数计算为
\[1 - \frac{\sum_{t=1}^T{(y_t - \hat{y}_t)^2}}{\sum_{t=1}^T{(y_t - \bar{y})^2}},\]其中 \(\bar{y}\) 是 \(y\) 在所有时间步上的平均值。
此度量不对称。
如果 \(\hat{y}_t\) 是随机的(包含多个样本)或分位数预测,请使用参数 q 指定计算度量的分位数。默认情况下,它使用中位数 0.5 分位数(对所有样本,或者如果给定,使用分位数预测本身)。
- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
],None
]) – 可选参数,要计算度量的分位数(浮点数 [0, 1])或分位数列表。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction 和 component_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有分量规约时,数组形状为 (n components * n quantiles,);在有分量规约且 len(q) > 1 时,形状为 (n quantiles,)。适用于
输入参数与上述返回 float 的情况相同,但 len(q) > 1。
单个多变量序列,且至少 component_reduction=None。
包含 series_reduction 的单变量/多变量序列,且 component_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
参考资料
- darts.metrics.metrics.rmse(actual_series, pred_series, intersect=True, *, q=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
均方根误差 (RMSE)。
对于长度为 \(T\) 的真实序列 \(y\) 和预测序列 \(\hat{y}\),它按分量/列和(可选)分位数计算为
\[\sqrt{\frac{1}{T}\sum_{t=1}^T{(y_t - \hat{y}_t)^2}}\]如果 \(\hat{y}_t\) 是随机的(包含多个样本)或分位数预测,请使用参数 q 指定计算度量的分位数。默认情况下,它使用中位数 0.5 分位数(对所有样本,或者如果给定,使用分位数预测本身)。
- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
],None
]) – 可选参数,要计算度量的分位数(浮点数 [0, 1])或分位数列表。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction 和 component_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有分量规约时,数组形状为 (n components * n quantiles,);在有分量规约且 len(q) > 1 时,形状为 (n quantiles,)。适用于
输入参数与上述返回 float 的情况相同,但 len(q) > 1。
单个多变量序列,且至少 component_reduction=None。
包含 series_reduction 的单变量/多变量序列,且 component_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
- darts.metrics.metrics.rmsle(actual_series, pred_series, intersect=True, *, q=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
均方根对数误差 (RMSLE)。
对于长度为 \(T\) 的真实序列 \(y\) 和预测序列 \(\hat{y}\),它按分量/列和(可选)分位数计算为
\[\sqrt{\frac{1}{T}\sum_{t=1}^T{\left(\log{(y_t + 1)} - \log{(\hat{y}_t + 1)}\right)^2}}\]使用自然对数。
如果 \(\hat{y}_t\) 是随机的(包含多个样本)或分位数预测,请使用参数 q 指定计算度量的分位数。默认情况下,它使用中位数 0.5 分位数(对所有样本,或者如果给定,使用分位数预测本身)。
- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
],None
]) – 可选参数,要计算度量的分位数(浮点数 [0, 1])或分位数列表。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction 和 component_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有分量规约时,数组形状为 (n components * n quantiles,);在有分量规约且 len(q) > 1 时,形状为 (n quantiles,)。适用于
输入参数与上述返回 float 的情况相同,但 len(q) > 1。
单个多变量序列,且至少 component_reduction=None。
包含 series_reduction 的单变量/多变量序列,且 component_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
- darts.metrics.metrics.rmsse(actual_series, pred_series, insample, m=1, intersect=True, *, q=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
均方根比例误差 (RMSSE)(关于比例预测误差的更多信息,请参见 [1])。
它是根据朴素 m 周期预测的 RMSE 缩放的均方根误差 (RMSE)。
对于长度为 \(T\) 的真实序列 \(y\) 和预测序列 \(\hat{y}\),它按分量/列和(可选)分位数计算为
\[\frac{RMSE(y_{t_p+1:t_p+T}, \hat{y}_{t_p+1:t_p+T})}{E_m},\]其中 \(t_p\) 是预测时间(第一个预测点前一步),\(RMSE\) 是均方根误差 (
rmse()
),\(E_m\) 是在 insample 序列 \(y_{0:t_p}\)(在 \(t_p\) 处结束的真实序列)上朴素 m 周期预测的 RMSE。\[E_m = RMSE(y_{m:t_p}, y_{0:t_p - m}).\]如果 \(\hat{y}_t\) 是随机的(包含多个样本)或分位数预测,请使用参数 q 指定计算度量的分位数。默认情况下,它使用中位数 0.5 分位数(对所有样本,或者如果给定,使用分位数预测本身)。
- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。insample (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 用于预测 pred_series 的训练序列。该序列用于计算朴素预测器在训练数据上获得的误差规模。m (
int
) – 用于计算误差规模 \(E_m\) 的差分季节性(如度量描述中所述)。\(m=1\) 对应于非季节性 \(E_m\)(例如朴素地重复最后一个观测值),而 \(m>1\) 对应于季节性 \(E_m\)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
],None
]) – 可选参数,要计算度量的分位数(浮点数 [0, 1])或分位数列表。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 引发
ValueError – 如果 insample 序列是周期性的( \(y_t = y_{t-m}\) ),或者 insample 中的任何序列没有在 pred_series 中对应预测的开始前一个时间步结束。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction 和 component_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有分量规约时,数组形状为 (n components * n quantiles,);在有分量规约且 len(q) > 1 时,形状为 (n quantiles,)。适用于
输入参数与上述返回 float 的情况相同,但 len(q) > 1。
单个多变量序列,且至少 component_reduction=None。
包含 series_reduction 的单变量/多变量序列,且 component_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
参考资料
- darts.metrics.metrics.sape(actual_series, pred_series, intersect=True, *, q=None, time_reduction=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
对称绝对百分比误差 (sAPE)。
对于长度为 \(T\) 的真实序列 \(y\) 和预测序列 \(\hat{y}\),它按分量/列、(可选) 分位数和时间步 \(t\) 计算为百分比值,公式如下:
\[200 \cdot \frac{\left| y_t - \hat{y}_t \right|}{\left| y_t \right| + \left| \hat{y}_t \right|}\]注意,如果对于某个 \(t\),\(\left| y_t \right| + \left| \hat{y}_t \right| = 0\),则会引发 ValueError。在这些情况下,请考虑使用绝对比例误差 (
ase()
)。如果 \(\hat{y}_t\) 是随机的(包含多个样本)或分位数预测,请使用参数 q 指定计算度量的分位数。默认情况下,它使用中位数 0.5 分位数(对所有样本,或者如果给定,使用分位数预测本身)。
- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
],None
]) – 可选参数,要计算度量的分位数(浮点数 [0, 1])或分位数列表。time_reduction (
Optional
[Callable
[…,ndarray
],None
]) – 可选参数,用于聚合时间轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (c,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于时间轴。如果为 None,则按每个时间步返回度量。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 引发
ValueError – 如果 actual_series 和 pred_series 在同一时间索引处包含零。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction、component_reduction 和 time_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有时间和分量规约时,数组形状为 (n time steps, n components * n quantiles);在没有时间规约但有分量规约且 len(q) > 1 时,形状为 (n time steps, n quantiles)。适用于
输入参数与上述返回 float 的情况相同,但 len(q) > 1。
单个多变量序列,且至少 component_reduction=None。
单个单变量/多变量序列,且至少 time_reduction=None。
包含 series_reduction 的单变量/多变量序列,且至少有一个 component_reduction=None 或 time_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
- darts.metrics.metrics.se(actual_series, pred_series, intersect=True, *, q=None, time_reduction=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
平方误差 (SE)。
对于长度为 \(T\) 的真实序列 \(y\) 和预测序列 \(\hat{y}\),它按分量/列、(可选) 分位数和时间步 \(t\) 计算为
\[(y_t - \hat{y}_t)^2.\]如果 \(\hat{y}_t\) 是随机的(包含多个样本)或分位数预测,请使用参数 q 指定计算度量的分位数。默认情况下,它使用中位数 0.5 分位数(对所有样本,或者如果给定,使用分位数预测本身)。
- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
],None
]) – 可选参数,要计算度量的分位数(浮点数 [0, 1])或分位数列表。time_reduction (
Optional
[Callable
[…,ndarray
],None
]) – 可选参数,用于聚合时间轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (c,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于时间轴。如果为 None,则按每个时间步返回度量。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction、component_reduction 和 time_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有时间和分量规约时,数组形状为 (n time steps, n components * n quantiles);在没有时间规约但有分量规约且 len(q) > 1 时,形状为 (n time steps, n quantiles)。适用于
输入参数与上述返回 float 的情况相同,但 len(q) > 1。
单个多变量序列,且至少 component_reduction=None。
单个单变量/多变量序列,且至少 time_reduction=None。
包含 series_reduction 的单变量/多变量序列,且至少有一个 component_reduction=None 或 time_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
- darts.metrics.metrics.sle(actual_series, pred_series, intersect=True, *, q=None, time_reduction=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
平方对数误差 (SLE)。
对于长度为 \(T\) 的真实序列 \(y\) 和预测序列 \(\hat{y}\),它按分量/列、(可选) 分位数和时间步 \(t\) 计算为
\[\left(\log{(y_t + 1)} - \log{(\hat{y} + 1)}\right)^2\]使用自然对数。
如果 \(\hat{y}_t\) 是随机的(包含多个样本)或分位数预测,请使用参数 q 指定计算度量的分位数。默认情况下,它使用中位数 0.5 分位数(对所有样本,或者如果给定,使用分位数预测本身)。
- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
],None
]) – 可选参数,要计算度量的分位数(浮点数 [0, 1])或分位数列表。time_reduction (
Optional
[Callable
[…,ndarray
],None
]) – 可选参数,用于聚合时间轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (c,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于时间轴。如果为 None,则按每个时间步返回度量。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction、component_reduction 和 time_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有时间和分量规约时,数组形状为 (n time steps, n components * n quantiles);在没有时间规约但有分量规约且 len(q) > 1 时,形状为 (n time steps, n quantiles)。适用于
输入参数与上述返回 float 的情况相同,但 len(q) > 1。
单个多变量序列,且至少 component_reduction=None。
单个单变量/多变量序列,且至少 time_reduction=None。
包含 series_reduction 的单变量/多变量序列,且至少有一个 component_reduction=None 或 time_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
- darts.metrics.metrics.smape(actual_series, pred_series, intersect=True, *, q=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
对称平均绝对百分比误差 (sMAPE)。
对于长度为 \(T\) 的真实序列 \(y\) 和预测序列 \(\hat{y}\),它按分量/列和(可选)分位数计算为百分比值,公式如下:
\[200 \cdot \frac{1}{T} \sum_{t=1}^{T}{\frac{\left| y_t - \hat{y}_t \right|}{\left| y_t \right| + \left| \hat{y}_t \right|} }\]注意,如果对于某个 \(t\),\(\left| y_t \right| + \left| \hat{y}_t \right| = 0\),则会引发 ValueError。在这些情况下,请考虑使用平均绝对比例误差 (
mase()
)。如果 \(\hat{y}_t\) 是随机的(包含多个样本)或分位数预测,请使用参数 q 指定计算度量的分位数。默认情况下,它使用中位数 0.5 分位数(对所有样本,或者如果给定,使用分位数预测本身)。
- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
],None
]) – 可选参数,要计算度量的分位数(浮点数 [0, 1])或分位数列表。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 引发
ValueError – 如果 actual_series 和 pred_series 在同一时间索引处包含零。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction 和 component_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有分量规约时,数组形状为 (n components * n quantiles,);在有分量规约且 len(q) > 1 时,形状为 (n quantiles,)。适用于
输入参数与上述返回 float 的情况相同,但 len(q) > 1。
单个多变量序列,且至少 component_reduction=None。
包含 series_reduction 的单变量/多变量序列,且 component_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
- darts.metrics.metrics.sse(actual_series, pred_series, insample, m=1, intersect=True, *, q=None, time_reduction=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
平方比例误差 (SSE)(关于比例预测误差的更多信息,请参见 [1])。
它是根据朴素 m 周期预测的平均 SE (MSE) 缩放的平方误差 (SE)。
对于长度为 \(T\) 的真实序列 \(y\) 和预测序列 \(\hat{y}\),它按分量/列、(可选) 分位数和时间步 \(t\) 计算为
\[\frac{SE(y_{t_p+1:t_p+T}, \hat{y}_{t_p+1:t_p+T})}{E_m},\]其中 \(t_p\) 是预测时间(第一个预测点前一步),\(SE\) 是平方误差 (
se()
),\(E_m\) 是在 insample 序列 \(y_{0:t_p}\)(在 \(t_p\) 处结束的真实序列)上朴素 m 周期预测的平均 SE (MSE)。\[E_m = MSE(y_{m:t_p}, y_{0:t_p - m}).\]如果 \(\hat{y}_t\) 是随机的(包含多个样本)或分位数预测,请使用参数 q 指定计算度量的分位数。默认情况下,它使用中位数 0.5 分位数(对所有样本,或者如果给定,使用分位数预测本身)。
- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。insample (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 用于预测 pred_series 的训练序列。该序列用于计算朴素预测器在训练数据上获得的误差规模。m (
int
) – 用于计算误差规模 \(E_m\) 的差分季节性(如度量描述中所述)。\(m=1\) 对应于非季节性 \(E_m\)(例如朴素地重复最后一个观测值),而 \(m>1\) 对应于季节性 \(E_m\)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
],None
]) – 可选参数,要计算度量的分位数(浮点数 [0, 1])或分位数列表。time_reduction (
Optional
[Callable
[…,ndarray
],None
]) – 可选参数,用于聚合时间轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (c,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于时间轴。如果为 None,则按每个时间步返回度量。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 引发
ValueError – 如果 insample 序列是周期性的( \(y_t = y_{t-m}\) ),或者 insample 中的任何序列没有在 pred_series 中对应预测的开始前一个时间步结束。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction、component_reduction 和 time_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有时间和分量规约时,数组形状为 (n time steps, n components * n quantiles);在没有时间规约但有分量规约且 len(q) > 1 时,形状为 (n time steps, n quantiles)。适用于
输入参数与上述返回 float 的情况相同,但 len(q) > 1。
单个多变量序列,且至少 component_reduction=None。
单个单变量/多变量序列,且至少 time_reduction=None。
包含 series_reduction 的单变量/多变量序列,且至少有一个 component_reduction=None 或 time_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
参考资料
- darts.metrics.metrics.wmape(actual_series, pred_series, intersect=True, *, q=None, component_reduction=<function nanmean>, series_reduction=None, n_jobs=1, verbose=False)[source]¶
加权平均绝对百分比误差 (WMAPE)。(关于更多信息,请参见 [1])。
对于长度为 \(T\) 的真实序列 \(y\) 和预测序列 \(\hat{y}\),它按分量/列和(可选)分位数计算为百分比值,公式如下:
\[100 \cdot \frac{\sum_{t=1}^T |y_t - \hat{y}_t|}{\sum_{t=1}^T |y_t|}\]如果 \(\hat{y}_t\) 是随机的(包含多个样本)或分位数预测,请使用参数 q 指定计算度量的分位数。默认情况下,它使用中位数 0.5 分位数(对所有样本,或者如果给定,使用分位数预测本身)。
- 参数
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 真实序列(或序列的序列)。pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – 预测序列(或序列的序列)。intersect (
bool
) – 对于时间索引不同但时间上重叠的时间序列,设置为 True 将仅考虑它们共同时间间隔(时间交集)内的值。q (
Union
[float
,list
[float
],tuple
[ndarray
,Index
],None
]) – 可选参数,要计算度量的分位数(浮点数 [0, 1])或分位数列表。component_reduction (
Optional
[Callable
[[ndarray
],float
],None
]) – 可选参数,用于聚合分量/列轴上度量的函数。它必须将形状为 (t, c) 的 np.ndarray 规约为形状为 (t,) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 1,对应于分量轴。如果为 None,则按每个分量返回度量。series_reduction (
Optional
[Callable
[[ndarray
],Union
[float
,ndarray
]],None
]) – 可选参数,用于聚合多个序列上度量的函数。它必须将形状为 (s, t, c) 的 np.ndarray 规约为形状为 (t, c) 的 np.ndarray。函数接受np.ndarray
作为输入,以及一个名为 axis 的参数,并返回规约后的数组。axis 的值为 0,对应于序列轴。例如,使用 np.nanmean 将返回所有序列度量的平均值。如果为 None,则按每个分量返回度量。n_jobs (
int
) – 并行运行的任务数量。只有当输入为Sequence[TimeSeries]
时才会创建并行任务,以并行处理不同的TimeSeries
。默认为 1(顺序执行)。将参数设置为 -1 表示使用所有可用的处理器。verbose (
bool
) – 可选参数,是否打印操作进度。
- 引发
ValueError – 如果 actual_series 包含零值。
- 返回类型
Union
[float
,list
[float
],ndarray
,list
[ndarray
]]- 返回
float – 单一度量分数(当 len(q) <= 1 时),适用于
单个单变量序列。
带有 component_reduction 的单个多变量序列。
带有 series_reduction 和 component_reduction 的单变量/多变量序列(列表)。
np.ndarray – 一个 numpy 数组,包含度量分数。在没有分量规约时,数组形状为 (n components * n quantiles,);在有分量规约且 len(q) > 1 时,形状为 (n quantiles,)。适用于
输入参数与上述返回 float 的情况相同,但 len(q) > 1。
单个多变量序列,且至少 component_reduction=None。
包含 series_reduction 的单变量/多变量序列,且 component_reduction=None。
list[float] – 与 float 类型相同,但适用于序列的序列。
list[np.ndarray] – 与 np.ndarray 类型相同,但适用于序列的序列。
参考资料