TATECHATLAS
◎ English
Math & models / Guide

Choosing a Forecast Functional and a Matching Loss for Time-Series Prediction

Fix the forecast target from the decision it supports, then train and evaluate with its strictly consistent loss: mean with squared error, median with absolute error, quantile with pinball loss.

On this page

Start from the decision the forecast supports, not from a familiar metric. If a contract or pipeline already fixes the scoring function, use it. Otherwise decide which property of the conditional response distribution you need: the mean for average-level decisions, the median for typical-value decisions robust to extremes, or a specific quantile for threshold and tail-risk decisions. Then pair it with a strictly consistent loss: squared error for the mean, absolute error for the median, pinball loss for a quantile, with the pinball alpha equal to the target quantile. Apply that same function as the training loss and as the evaluation metric so that fitting and model comparison measure the same target functional.

Define the forecast goal before choosing a metric

The scoring function is not a neutral technical detail; it encodes which forecast counts as correct. If a business context, competition, or existing pipeline already supplies the metric, use that one. If you are free to choose, begin with the ultimate goal and application of the prediction: what action changes when the number moves, which errors are costly, and whether the decision concerns an average level, a typical day, or an extreme tail.

Keep two steps separate. Producing the prediction means selecting one property of the response distribution conditional on the features. Making the decision means converting that number into an action. Only after the required property is fixed does it make sense to select a loss, because the loss is what makes the estimator and the evaluator target that property.

Choose the target functional: mean, median, or quantile

The mean, or expected value, is the right functional when deviations above and below the forecast are treated symmetrically and large misses should be penalized heavily. It is the natural target for average demand, average load, or average cost planning.

The median is the 0.5 quantile. It is the right functional when the cost grows linearly with the size of the miss and a few extreme observations should not dominate the fitted value. It answers the question of what a typical observation looks like.

A quantile alpha is the right functional when the decision is a threshold: capacity headroom, a service-level promise, a safety margin, or a budget ceiling. Choosing alpha is a business decision, not a tuning detail, and the forecast must be interpreted at that same level.

Match a strictly consistent loss to the chosen functional

A strictly consistent scoring function has the property that its expected value is minimized exactly at the target functional, so reporting the truth is optimal in expectation. This is the guarantee that connects a loss to a specific summary of the distribution.

The standard regression pairs are: mean with mean squared error, median with mean absolute error, and a quantile with pinball loss whose alpha equals that quantile. Related squared-error deviances such as Poisson, Gamma, and Tweedie deviance target a mean under their own distributional conditions. The alpha mismatch is a real error: training at 0.95 and scoring at 0.99 optimizes and evaluates different targets.

Use the same function for training and evaluation

Once a strictly consistent function is chosen, use it both as the loss during model fitting and as the metric during evaluation and model comparison. This keeps optimization and validation aligned: the model is pushed toward the functional that the comparison later rewards.

A probability training loss and a downstream decision metric may legitimately differ in probabilistic forecasting, but for a point forecast of a fixed functional the practical default is alignment. If a separate business KPI exists, report it in addition to the consistent metric rather than silently substituting it.

Worked example: the 0.99 quantile and pinball loss

Suppose a network provider promises that on at least 99% of days there is no interruption longer than one minute, so the target functional is the 0.99 quantile of the longest daily interruption. Training uses a quantile loss at 0.99 and evaluation uses mean pinball loss at alpha 0.99, for example in a grid search comparing HistGradientBoostingRegressor(loss="quantile", quantile=0.99) with QuantileRegressor(quantile=0.99). The argument names differ between the estimator and the metric, but the level must be identical.

The example below uses scikit-learn 1.4 or later, because root_mean_squared_error was added in version 1.4. It shows how the three metrics respond to the same five observations; the printed values are illustrative output computed from the shown input.

The pinball value 2.594 reflects the 0.99 asymmetry, so underprediction of high values costs far more than overprediction. MAE 4.6 and RMSE 5.0398 are reported only to show that they answer a different question, namely absolute and squared deviation from the observed values, not tail risk.

from sklearn.metrics import mean_pinball_loss, mean_absolute_error, root_mean_squared_error

y_true = [12, 30, 5, 48, 20]
y_pred = [15, 25, 10, 40, 22]

print(round(mean_pinball_loss(y_true, y_pred, alpha=0.99), 4))
print(round(mean_absolute_error(y_true, y_pred), 4))
print(round(root_mean_squared_error(y_true, y_pred), 4))

# Illustrative output:
# 2.594
# 4.6
# 5.0398

Interpret metric values and aggregation parameters

MAE and RMSE are non-negative floating point values whose best value is 0.0, so lower is better and the units follow the target. RMSE is not generally the standard deviation of the errors; that equality additionally requires zero-mean errors and a matching divisor, and the square root must be preserved whenever RMSE is reported or translated.

Both functions accept multioutput. The value raw_values returns one error per output, uniform_average averages outputs with equal weight, and an array of weights averages them with the given weights. This choice changes the reported number, so state it when comparing multi-output forecasts. MAE gives each absolute error a linear, unbounded contribution: it is less dominated by outliers than squared loss, but it is not immune to extreme errors.

Compare models through the shared scoring interface

String scoring names connect metrics to hyperparameter search and cross-validation: neg_mean_absolute_error, neg_root_mean_squared_error, and neg_median_absolute_error. They return the negated metric because the search maximizes a score, so a value closer to zero is better and a more negative value is worse.

For quantile targets, pass a callable scorer built from mean_pinball_loss with the required alpha rather than assuming a string name exists. Verify the scorer response contract of the version in use: some scorers return a float, while others return a dict, and the search API must accept the returned type.

Scope limits of the chosen pair

These pairs belong to regression. They do not transfer automatically to classification, where strictly proper scoring rules for probabilistic predictions play the analogous role. For the mode, no consistent scoring function exists, and zero-one loss is only consistent, not strictly consistent, so the scheme above does not apply to it.

The guidance explains how to select a functional and a matching loss; it does not diagnose why a particular model performs poorly, does not choose the forecasting algorithm, and does not establish that 0.99 is the correct level in another task. Time-series splitting, leakage from lagged features, and the independence of evaluation labels remain separate responsibilities of the evaluation design.

Things to check

  • The target functional is stated before any metric is named
  • The pinball alpha equals the quantile used for training
  • Mean, median, and quantile are paired with MSE, MAE, and pinball loss
  • The same function is used for training and for evaluation
  • MAE and RMSE are described as non-negative with best value 0
  • RMSE is not called the standard deviation of errors without conditions
  • multioutput raw_values, uniform_average, and weights are distinguished
  • Negative scoring names are explained as a maximization convention
  • The mode and zero-one loss limitations are stated
  • Regression pairs are not presented as classification claims

The material covers selection of a functional and a consistent loss, not diagnosis of a specific model's errors or choice of a forecasting algorithm. The pairs (mean, MSE), (median, MAE), and (quantile, pinball loss) apply to regression and do not extend to classification without separate justification. No consistent function exists for the mode, and zero-one loss is only consistent, not strictly consistent. The 0.99 quantile example is illustrative and does not imply that level is correct elsewhere. Code assumes scikit-learn 1.4 or later for root_mean_squared_error.

Sources

  1. scikit-learn: model evaluation ↗
  2. scikit-learn: mean_absolute_error ↗
  3. scikit-learn: root_mean_squared_error ↗
Back to top ↑