TATECHATLAS
◎ English
Math & models / Guide

Aggregating Forecast Errors Across Multiple Output Series in scikit-learn

Learn how to use raw_values, uniform_average, and custom weights in scikit-learn's multioutput parameter to detect per‑series degradation and choose the right aggregation for forecasting goals.

On this page

When evaluating multi‑output regression models such as time‑series forecasters, a single aggregated metric (the default uniform_average) can hide high errors on a critical series. Use multioutput='raw_values' to inspect each series separately, choose uniform_average for equal importance, use variance_weighted for R²/explained_variance when series differ in spread, or pass a 1‑D weight array to reflect business priorities. Always report both per‑series and aggregated metrics to avoid misleading conclusions.

Understanding Multi‑output Error Aggregation

When a model predicts multiple time‑series or multiple horizons at once, scikit‑learn's regression metrics (e.g., mean_absolute_error, mean_squared_error) need to combine the error of each output dimension into a single number. The choice of how to combine them affects whether a poor forecast on one series is visible in the overall score.

The default behaviour is uniform_average, which simply averages the per‑series errors with equal weight. This is convenient but can mask problems if series have different scales, frequencies, or business importance.

Other options - raw_values, variance_weighted, and custom weight arrays - let you inspect or emphasise particular series, making degradation detectable early in model evaluation.

In forecasting, start by computing MAE with raw_values. If any series shows an error above your tolerance, decide whether to apply weights or investigate that series before relying on the uniform average for model selection.

raw_values: Inspecting Every Series Separately

Setting multioutput='raw_values' returns an array whose entry i is the MAE (or chosen metric) computed only on the i‑th output series. The shape of the returned array is (n_outputs,).

This allows you to see exactly how each series performed: a high value on one entry immediately signals a potential issue, while the overall uniform average might still look acceptable.

Use raw_values when you want diagnostic insight, when series have heterogeneous scales, or when you need to feed per‑series errors into downstream monitoring.

uniform_average: The Default One‑Size‑Fits‑All

By default multioutput='uniform_average' computes the metric for each series and then takes a simple arithmetic mean. Mathematically, if e_i is the per‑series error, the aggregated error is (e_1 + … + e_k)/k.

This approach is easy to explain and works well when all series are on the same scale and have equal importance (e.g., forecasting a single aggregated demand).

However, if one series varies over a larger range or carries higher business risk, the uniform average can dilute that series’ poor performance, leading to a misleadingly low overall score.

variance_weighted: Scaling by Target Variance

For r2_score and explained_variance_score, scikit-learn offers multioutput='variance_weighted'. Each series is weighted by the variance of the corresponding target variable, so series with greater spread receive proportionally more influence on the global score.

This reflects the intuition that explaining more variable data should be harder and more important. It is useful when series differ in natural variability rather than in absolute scale.

Note that variance_weighted is not available for MAE or MSE; it is specific to the variance‑based scores.

Custom Weight Arrays: Prioritizing Business Value

You can pass a 1‑D array of shape (n_outputs,) as the multioutput argument. The entries act as weights; the final score is the weighted average of the per‑series errors: Σ w_i * e_i / Σ w_i.

Choose weights that match business priorities (e.g., give twice the weight to a safety‑critical series) or forecast horizons (e.g., longer‑term horizons may be less critical for daily operations).

Weights must sum to any positive value; normalising them (e.g., to sum to 1) often improves interpretability. Ensure the weight array length equals the number of output columns; otherwise scikit‑learn raises a ValueError.

Choosing the Right Metric for Forecasting Horizons

When evaluating a forecasting model, clarify the goal: short‑term accuracy for operational decisions versus long‑term trend capture for strategic planning. Short‑term horizons often benefit from MAE (linear penalty) while longer horizons may tolerate occasional larger errors.

If horizons differ in importance (e.g., day‑ahead demand is critical, week‑ahead is for planning), use custom weights rather than uniform averaging. If horizons are similar and series are on comparable scales, uniform_average remains simple and adequate.

Refer to the scikit-learn model evaluation guide for guidance on selecting scoring functions aligned with the prediction functional (mean, quantile, etc.).

Practical Example: Forecasting Two Time Series

We compute MAE on two synthetic series using pre-defined true and predicted arrays: series A with per-sample absolute errors of 1.0 and series B with per-sample absolute errors of 0.1. Three aggregation modes are compared: raw_values, uniform_average, and a custom weight array [2, 1]. The expected output is: MAE per series (raw_values): [1. 0.1], Uniform MAE: 0.55, Weighted MAE (weights [2,1]): 0.7. These values follow directly from the arithmetic: (1.0+0.1)/2 = 0.55 for uniform, and (2*1.0 + 1*0.1)/(2+1) = 0.7 for weighted.

The code uses raw_values to list per‑series errors, uniform_average for the default single number, and a custom weight array [2, 1] to give series A twice the importance of series B.

The example demonstrates that raw_values can reveal that series A has a higher MAE while the uniform average might appear acceptable, prompting a closer look at series A's forecast quality.

import numpy as np
from sklearn.metrics import mean_absolute_error

# Two series: series A (high variance), series B (low variance)
y_true = np.array([[10, 1], [12, 1.2], [9, 0.8], [11, 1.1]])
y_pred = np.array([[9, 1.1], [13, 1.3], [8, 0.9], [10, 1.0]])

# raw_values
mae_raw = mean_absolute_error(y_true, y_pred, multioutput='raw_values')
# uniform_average (default)
mae_uniform = mean_absolute_error(y_true, y_pred)
# custom weights: give series A twice the importance of B
weights = np.array([2, 1])
mae_weighted = mean_absolute_error(y_true, y_pred, multioutput=weights)

print('MAE per series (raw_values):', mae_raw)
print('Uniform MAE:', mae_uniform)
print('Weighted MAE (weights [2,1]):', mae_weighted)

# Expected output:
# MAE per series (raw_values): [1.  0.1]
# Uniform MAE: 0.55
# Weighted MAE (weights [2,1]): 0.7

When a Single Number is Misleading

Consider a scenario where series A (critical safety stock) consistently under‑predicts by 5 units, while series B (auxiliary inventory) is accurate within 0.5 units. Using the default uniform_average might yield a modest overall MAE of 2.5, suggesting good performance, even though series A is failing.

Suppose a hypothetical scenario where series A shows a per-series MAE of 5.0 and series B shows 0.3; with weights [2,1] the weighted MAE would be (2*5.0 + 1*0.3)/3 = 3.43. By reporting both the raw per-series MAEs and the weighted MAE, stakeholders see the true risk. The uniform average alone hides the degradation on the critical series.

Best practice: always include raw_values diagnostics in monitoring dashboards and use custom weights when business priorities differ across series. Reserve the single aggregated number for high‑level summaries after confirming that no series exceeds predefined tolerance thresholds.

Things to check

  • raw_values returns an array of shape (n_outputs,) and does not perform any averaging
  • uniform_average computes the arithmetic mean of per‑series errors
  • custom weights must be a 1‑D array of length n_outputs and are normalised by their sum
  • variance_weighted is only supported for r2_score and explained_variance_score
  • weights that sum to zero are undefined for a weighted average; the documentation does not specify the exact exception type raised in that case
  • When multioutput is 'raw_values', the function returns per-series errors without any weighting or averaging

Aggregations are only defined for numeric targets; categorical or probabilistic forecasts require different metrics. Raw_values returns a NumPy array; conversion to DataFrame must be done manually. Custom weights must match the number of output columns; mismatched shapes raise a ValueError. The variance_weighted mode is specific to r2_score and explained_variance_score and cannot be used with MAE or MSE.

Sources

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