median_squared_error#
- median_squared_error(y_true, y_pred, horizon_weight=None, multioutput='uniform_average', square_root=False, **kwargs)[源代码]#
中值平方误差 (MdSE) 或均方根中值平方误差 (RMdSE)。
如果
square_root
为 False,则计算 MdSE;如果为 True,则计算 RMdSE。MdSE 和 RMdSE 都返回非负浮点数。最优值为 0.0。与 MSE 类似,MdSE 的度量单位是输入数据的平方单位。RMdSE 与 RMSE 一样,度量单位与输入数据相同。由于 MdSE 和 RMdSE 使用平方预测误差而不是绝对值,它们对大误差的惩罚比 MAE 或 MdAE 更重。
与基于均值的度量相比,取平方误差的中值而不是均值使得该度量对误差离群值更具鲁棒性,因为在存在离群值的情况下,中值通常是衡量集中趋势的更稳健的指标。
- 参数:
- 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_weightshape 为 (fh,) 的 array-like 对象,默认值为 None
预测范围权重。
- multioutput{‘raw_values’, ‘uniform_average’} 或 shape 为 (n_outputs,) 的 array-like 对象,默认值为 ‘uniform_average’
定义如何聚合多元(多输出)数据的度量。如果为 array-like 对象,则值用作权值来平均误差。如果为 ‘raw_values’,则在多输出输入的情况下返回完整的误差集合。如果为 ‘uniform_average’,则所有输出的误差以均匀权值进行平均。
- square_rootbool,默认值为 False
是否对平方误差的中值取平方根。如果为 True,返回均方根中值平方误差 (RMdSE)。如果为 False,返回中值平方误差 (MdSE)。
- 返回:
- lossfloat
MdSE 损失。如果 multioutput 为 ‘raw_values’,则为每个输出分别返回 MdSE。如果 multioutput 为 ‘uniform_average’ 或一个权重 ndarray,则返回所有输出误差的加权平均 MdSE。
参考文献
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 median_squared_error >>> y_true = np.array([3, -0.5, 2, 7, 2]) >>> y_pred = np.array([2.5, 0.0, 2, 8, 1.25]) >>> median_squared_error(y_true, y_pred) 0.25 >>> median_squared_error(y_true, y_pred, square_root=True) 0.5 >>> y_true = np.array([[0.5, 1], [-1, 1], [7, -6]]) >>> y_pred = np.array([[0, 2], [-1, 2], [8, -5]]) >>> median_squared_error(y_true, y_pred) 0.625 >>> median_squared_error(y_true, y_pred, square_root=True) 0.75 >>> median_squared_error(y_true, y_pred, multioutput='raw_values') array([0.25, 1. ]) >>> median_squared_error(y_true, y_pred, multioutput='raw_values', square_root=True) array([0.5, 1. ]) >>> median_squared_error(y_true, y_pred, multioutput=[0.3, 0.7]) 0.7749999999999999 >>> median_squared_error(y_true, y_pred, multioutput=[0.3, 0.7], square_root=True) 0.85