skills/timeseries/mean-residual-decomposition/SKILL.md
Decompose multi-output prediction into a global mean (1D model) plus per-channel residuals (2D model) with quadrature uncertainty
npx skillsauth add wenmin-wu/ds-skills timeseries-mean-residual-decompositionInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
For multi-output regression where outputs share a common baseline (e.g. spectrum = mean depth + per-wavelength variation), train two models: one predicts the global mean from a summary signal, another predicts per-channel residuals. Final prediction = mean + residuals. Uncertainty propagates in quadrature.
import numpy as np
def predict_decomposed(mean_model, residual_model, summary_input, detail_input,
n_mc=100):
"""Predict via mean + residual decomposition with MC uncertainty."""
# Mean prediction (1D)
mean_preds = np.stack([mean_model(summary_input, training=True)
for _ in range(n_mc)])
mean_val = mean_preds.mean(axis=0)
mean_std = mean_preds.std(axis=0)
# Residual prediction (2D)
res_preds = np.stack([residual_model(detail_input, training=True)
for _ in range(n_mc)])
res_val = res_preds.mean(axis=0)
res_std = res_preds.std(axis=0)
# Combine
prediction = res_val + mean_val[:, np.newaxis]
uncertainty = np.sqrt(mean_std[:, np.newaxis]**2 + res_std**2)
return prediction, uncertainty
σ_total = √(σ_mean² + σ_residual²) — independent uncertaintiesdata-ai
Scaled Pinball Loss (SPL) metric for evaluating quantile forecasts, normalized by mean absolute successive differences of training data
data-ai
Walk backward through a time series and multiplicatively rescale segments when jumps exceed a fraction of the running mean to correct data collection anomalies
testing
Transform forecasting target to next/current ratio minus one so that optimizing MAE or squared error implicitly minimizes SMAPE
tools
Convert point forecasts to prediction intervals by scaling with logit-transformed quantile ratios passed through a Normal CDF