geometric_mean_squared_error#
- geometric_mean_squared_error(y_true, y_pred, horizon_weight=None, multioutput='uniform_average', square_root=False, **kwargs)[source]#
几何平均平方误差 (GMSE) 或 根几何平均平方误差 (RGMSE)。
如果
square_root
为 False,则计算 GMSE;如果square_root
为 True,则计算 RGMSE。GMSE 和 RGMSE 都返回非负浮点数。最优值约为零,而不是恰好为零。与 MSE 和 MdSE 一样,GMSE 的度量单位是输入数据的平方单位。RGMSE 与 RMSE 和 RdMSE 一样,与输入数据的尺度相同。由于 GMSE 和 RGMSE 对预测误差进行平方而不是取绝对值,因此它们对大误差的惩罚比 GMAE 更大。
- 参数:
- y_truepd.Series, pd.DataFrame 或 shape 为 (fh,) 或 (fh, n_outputs) 的 np.array,其中 fh 是预测范围
真实(正确)目标值。
- y_predpd.Series, pd.DataFrame 或 shape 为 (fh,) 或 (fh, n_outputs) 的 np.array,其中 fh 是预测范围
预测值。
- horizon_weight形状为 (fh,) 的类数组对象,默认为 None
预测范围权重。
- multioutput{‘raw_values’, ‘uniform_average’} 或形状为 (n_outputs,) 的类数组对象,默认为 ‘uniform_average’
定义如何聚合多变量(多输出)数据的度量。如果是类数组对象,则值用作对误差进行平均的权重。如果是 ‘raw_values’,则在多输出输入的情况下返回完整的误差集合。如果是 ‘uniform_average’,则所有输出的误差将以均匀权重进行平均。
- square_rootbool,默认为 False
是否取均方误差的平方根。如果为 True,返回根几何平均平方误差 (RGMSE)。如果为 False,返回几何平均平方误差 (GMSE)。
- 返回:
- lossfloat
GMSE 或 RGMSE 损失。如果 multioutput 为 ‘raw_values’,则为每个输出分别返回损失。如果 multioutput 为 ‘uniform_average’ 或一个权重 ndarray,则返回所有输出误差的加权平均 MdSE。
另请参阅
注释
几何平均数在其计算中使用了值的乘积。零值的存在将导致结果为零,即使所有其他值都很大。为了部分解决
y_true
和y_pred
的元素相等(误差为零)的情况,计算中将结果为零的误差值替换为一个小值。这使得该指标可以采用的最小值(当y_true
等于y_pred
时)接近但不完全为零。参考文献
Hyndman, R. J and Koehler, A. B. (2006). “Another look at measures of forecast accuracy”, International Journal of Forecasting, Volume 22, Issue 4.
示例
>>> import numpy as np >>> from sktime.performance_metrics.forecasting import geometric_mean_squared_error as gmse >>> y_true = np.array([3, -0.5, 2, 7, 2]) >>> y_pred = np.array([2.5, 0.0, 2, 8, 1.25]) >>> gmse(y_true, y_pred) 2.80399089461488e-07 >>> gmse(y_true, y_pred, square_root=True) 0.000529527232030127 >>> y_true = np.array([[0.5, 1], [-1, 1], [7, -6]]) >>> y_pred = np.array([[0, 2], [-1, 2], [8, -5]]) >>> gmse(y_true, y_pred) 0.5000000000115499 >>> gmse(y_true, y_pred, square_root=True) 0.5000024031086919 >>> gmse(y_true, y_pred, multioutput='raw_values') array([2.30997255e-11, 1.00000000e+00]) >>> gmse(y_true, y_pred, multioutput='raw_values', square_root=True) array([4.80621738e-06, 1.00000000e+00]) >>> gmse(y_true, y_pred, multioutput=[0.3, 0.7]) 0.7000000000069299 >>> gmse(y_true, y_pred, multioutput=[0.3, 0.7], square_root=True) 0.7000014418652152