Skip to content

ConstraintViolation

ConstraintViolation

class ConstraintViolation(multioutput='uniform_average', score_average=True, coverage=None)[source]

Average absolute constraint violations for interval predictions.

Applies to interval predictions.

Should be used together with EmpiricalCoverage if reported.

Up to a constant, PinballLoss is a weighted sum of ConstraintViolation and EmpiricalCoverage.

For an interval prediction \(I = [a, b]\) and a ground truth value \(y\), the constraint violation loss is defined as

\[\begin{split}L(y, I) := \begin{cases} a - y, & \text{if } y < a \\ y - b, & \text{if } y > b \\ 0, & \text{otherwise} \end{cases}\end{split}\]
  • evaluate computes the average test sample loss.

  • evaluate_by_index produces the loss sample by test data point.

  • multivariate controls averaging over variables.

  • score_average controls averaging over quantiles/intervals.

Parameters:
multioutput‘uniform_average’ (default), 1D array-like, or ‘raw_values’

Whether and how to aggregate metric for multivariate (multioutput) data.

  • If 'uniform_average' (default), errors of all outputs are averaged with uniform weight.

  • If 1D array-like, errors are averaged across variables, with values used as averaging weights (same order).

  • If 'raw_values', does not average across variables (outputs), per-variable errors are returned.

score_averagebool, optional, default = True

specifies whether scores for each coverage value should be averaged.

  • If True, metric/loss is averaged over all coverages present in y_pred.

  • If False, metric/loss is not averaged over coverages.

coverage (optional)float, list of float, or 1D array-like, default=None

nominal coverage to evaluate metric at. Can be specified if no explicit coverages are present in the direct use of the metric, for instance in benchmarking via evaluate, or tuning via ForecastingGridSearchCV.

Methods

__call__(y_true, y_pred, **kwargs)

Calculate metric value using underlying metric function.

__call__(y_true, y_pred, **kwargs)[source]

Calculate metric value using underlying metric function.

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_predreturn object of probabilistic prediction method scitype:y_pred

must be at fh and for variables equal to those in y_true.

Returns:
lossfloat or 1-column pd.DataFrame with calculated metric value(s)

metric is always averaged (arithmetic) over fh values if multioutput = “raw_values”,

will have a column level corresponding to variables in y_true

if multioutput = multioutput = “uniform_average” or or array-like

entries will be averaged over output variable column

if score_average = False,

will have column levels corresponding to quantiles/intervals

if score_average = True,

entries will be averaged over quantiles/interval column