非对称平均误差#
- mean_asymmetric_error(y_true, y_pred, asymmetric_threshold=0.0, left_error_function='squared', right_error_function='absolute', left_error_penalty=1.0, right_error_penalty=1.0, horizon_weight=None, multioutput='uniform_average', **kwargs)[源代码]#
计算非对称损失函数的平均值。
输出是非负浮点数。最优值为 0.0。
小于非对称阈值的误差值应用
left_error_function
。大于或等于非对称阈值的误差值应用right_error_function
。许多预测损失函数(例如 [1] 中讨论的)假设预测过高和过低应受到相同的惩罚。然而,这可能与预测用户面临的实际成本不符。当预测过低和过高的成本不同时,非对称损失函数非常有用。
将
asymmetric_threshold
设置为零,left_error_function
设置为 ‘squared’,right_error_function
设置为 ‘absolute’ 会对预测过高 (y_true - y_pred < 0) 施加更大的惩罚。而将left_error_function
设置为 ‘absolute’,right_error_function
设置为 ‘squared’ 则相反。left_error_penalty
和right_error_penalty
可用于对预测过高和过低施加不同的乘法惩罚。- 参数:
- y_truepd.Series, pd.DataFrame 或 np.array,形状为 (fh,) 或 (fh, n_outputs),其中 fh 是预测范围
真实(正确)目标值。
- y_predpd.Series, pd.DataFrame 或 np.array,形状为 (fh,) 或 (fh, n_outputs),其中 fh 是预测范围
预测值。
- asymmetric_thresholdfloat, 默认值 = 0.0
用于设置非对称损失函数阈值的值。小于非对称阈值的误差值应用
left_error_function
。大于或等于非对称阈值的误差值应用right_error_function
。- left_error_function{‘squared’, ‘absolute’}, 默认值=’squared’
应用于小于非对称阈值的误差值的损失惩罚函数。
- right_error_function{‘squared’, ‘absolute’}, 默认值=’absolute’
应用于大于或等于非对称阈值的误差值的损失惩罚函数。
- left_error_penaltyint 或 float, 默认值=1.0
对小于非对称阈值的误差值应用的额外乘法惩罚。
- right_error_penaltyint 或 float, 默认值=1.0
对大于非对称阈值的误差值应用的额外乘法惩罚。
- horizon_weightarray-like,形状为 (fh,), 默认值=None
预测范围权重。
- multioutput{‘raw_values’, ‘uniform_average’} 或 array-like 形状为 (n_outputs,), 默认值=’uniform_average’
定义如何聚合多变量(多输出)数据的指标。如果为 array-like,则其值用作权重来平均误差。如果为 ‘raw_values’,则在多输出输入情况下返回完整的误差集。如果为 ‘uniform_average’,则所有输出的误差以统一权重进行平均。
- 返回值:
- asymmetric_lossfloat
对误差施加非对称惩罚的损失值。如果 multioutput 是 ‘raw_values’,则分别返回每个输出的非对称损失。如果 multioutput 是 ‘uniform_average’ 或一个权重 ndarray,则返回所有输出误差的加权平均非对称损失。
另请参阅
说明
将
left_error_function
和right_error_function
都设置为 “absolute”,但为left_error_penalty
和right_error_penalty
选择不同的值,将产生 [2] 中讨论的 “lin-lin” 误差函数。参考文献
[1]Hyndman, R. J and Koehler, A. B. (2006). “Another look at measures of forecast accuracy”, International Journal of Forecasting, Volume 22, Issue 4.
[2]Diebold, Francis X. (2007). “Elements of Forecasting (4th ed.)”, Thomson, South-Western: Ohio, US.
示例
>>> import numpy as np >>> from sktime.performance_metrics.forecasting import mean_asymmetric_error >>> y_true = np.array([3, -0.5, 2, 7, 2]) >>> y_pred = np.array([2.5, 0.0, 2, 8, 1.25]) >>> mean_asymmetric_error(y_true, y_pred) 0.5 >>> mean_asymmetric_error(y_true, y_pred, left_error_function='absolute', right_error_function='squared') 0.4625 >>> y_true = np.array([[0.5, 1], [-1, 1], [7, -6]]) >>> y_pred = np.array([[0, 2], [-1, 2], [8, -5]]) >>> mean_asymmetric_error(y_true, y_pred) 0.75 >>> mean_asymmetric_error(y_true, y_pred, left_error_function='absolute', right_error_function='squared') 0.7083333333333334 >>> mean_asymmetric_error(y_true, y_pred, multioutput='raw_values') array([0.5, 1. ]) >>> mean_asymmetric_error(y_true, y_pred, multioutput=[0.3, 0.7]) 0.85