# mean_linex_error#

mean_linex_error(y_true, y_pred, a=1.0, b=1.0, horizon_weight=None, multioutput='uniform_average', **kwargs)[source]#

Calculate mean linex error.

Output is non-negative floating point. The best value is 0.0.

Many forecasting loss functions (like those discussed in [R604c24f92071-1]) assume that over- and under- predictions should receive an equal penalty. However, this may not align with the actual cost faced by users’ of the forecasts. Asymmetric loss functions are useful when the cost of under- and over- prediction are not the same.

The linex error function accounts for this by penalizing errors on one side of a threshold approximately linearly, while penalizing errors on the other side approximately exponentially.

Parameters
y_truepd.Series, pd.DataFrame or np.array of shape (fh,) or (fh, n_outputs) where fh is the forecasting horizon

Ground truth (correct) target values.

y_predpd.Series, pd.DataFrame or np.array of shape (fh,) or (fh, n_outputs) where fh is the forecasting horizon

Forecasted values.

aint or float

Controls whether over- or under- predictions receive an approximately linear or exponential penalty. If a > 0 then negative errors (over-predictions) are penalized approximately linearly and positive errors (under-predictions) are penalized approximately exponentially. If a < 0 the reverse is true.

bint or float

Multiplicative penalty to apply to calculated errors.

horizon_weightarray-like of shape (fh,), default=None

Forecast horizon weights.

multioutput{‘raw_values’, ‘uniform_average’} or array-like of shape (n_outputs,), default=’uniform_average’

Defines how to aggregate metric for multivariate (multioutput) data. If array-like, values used as weights to average the errors. If ‘raw_values’, returns a full set of errors in case of multioutput input. If ‘uniform_average’, errors of all outputs are averaged with uniform weight.

Returns
asymmetric_lossfloat

Loss using asymmetric penalty of on errors. If multioutput is ‘raw_values’, then asymmetric loss is returned for each output separately. If multioutput is ‘uniform_average’ or an ndarray of weights, then the weighted average asymmetric loss of all output errors is returned.

Notes

Calculated as b * (np.exp(a * error) - a * error - 1), where a != 0 and b > 0 according to formula in _.

References

1

Hyndman, R. J and Koehler, A. B. (2006). “Another look at measures of forecast accuracy”, International Journal of Forecasting, Volume 22, Issue 4.

1

Diebold, Francis X. (2007). “Elements of Forecasting (4th ed.)”, Thomson, South-Western: Ohio, US.

Examples

```>>> import numpy as np
>>> from sktime.performance_metrics.forecasting import mean_linex_error
>>> y_true = np.array([3, -0.5, 2, 7, 2])
>>> y_pred = np.array([2.5, 0.0, 2, 8, 1.25])
>>> mean_linex_error(y_true, y_pred)
0.19802627763937575
>>> mean_linex_error(y_true, y_pred, b=2)
0.3960525552787515
>>> mean_linex_error(y_true, y_pred, a=-1)
0.2391800623225643
>>> y_true = np.array([[0.5, 1], [-1, 1], [7, -6]])
>>> y_pred = np.array([[0, 2], [-1, 2], [8, -5]])
>>> mean_linex_error(y_true, y_pred)
0.2700398392309829
>>> mean_linex_error(y_true, y_pred, a=-1)
0.49660966225813563
>>> mean_linex_error(y_true, y_pred, multioutput='raw_values')
array([0.17220024, 0.36787944])
>>> mean_linex_error(y_true, y_pred, multioutput=[0.3, 0.7])
0.30917568000716666
```
{"ft_lang_label":"__label__en","ft_lang_prob":0.6978396,"math_prob":0.9444559,"size":3372,"snap":"2022-40-2023-06","text_gpt3_token_len":919,"char_repetition_ratio":0.1347981,"word_repetition_ratio":0.048565123,"special_character_ratio":0.3122776,"punctuation_ratio":0.21103896,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9980265,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-10-04T01:01:46Z\",\"WARC-Record-ID\":\"<urn:uuid:5a6b408a-94bc-4df0-8865-17188c345a27>\",\"Content-Length\":\"82466\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:ac70bced-8cd1-4ae6-877c-98487e90ce1f>\",\"WARC-Concurrent-To\":\"<urn:uuid:0c65303d-55a2-460f-a501-7c35f44a762b>\",\"WARC-IP-Address\":\"104.17.32.82\",\"WARC-Target-URI\":\"https://www.sktime.org/en/stable/api_reference/auto_generated/sktime.performance_metrics.forecasting.mean_linex_error.html\",\"WARC-Payload-Digest\":\"sha1:DTYUW66K2J43VEJ47LMJRKZUU6YGBDSP\",\"WARC-Block-Digest\":\"sha1:YKGSAG2ZQ7O4QGK6J5QXFYMZGBZZNPHE\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-40/CC-MAIN-2022-40_segments_1664030337446.8_warc_CC-MAIN-20221003231906-20221004021906-00072.warc.gz\"}"}