skills/timeseries/hierarchy-level-confidence-coefficients/SKILL.md
Assign different uncertainty spread coefficients per aggregation level in hierarchical forecasts, reflecting that higher aggregation yields narrower intervals
npx skillsauth add wenmin-wu/ds-skills timeseries-hierarchy-level-confidence-coefficientsInstall 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.
In hierarchical time series (item → department → category → store → state → total), higher aggregation levels are smoother and have narrower prediction intervals. When converting point forecasts to quantiles via ratio scaling, assign a different bandwidth coefficient per hierarchy level — wider for individual items (high variance), narrower for totals (low variance). This produces better-calibrated intervals across all levels without training separate quantile models.
from scipy import stats
import numpy as np
import pandas as pd
def get_ratios(quantiles, coef=0.15):
qs = np.array(quantiles)
logit_qs = np.log(qs / (1 - qs)) * coef
ratios = stats.norm.cdf(logit_qs)
ratios /= ratios[len(ratios) // 2]
return pd.Series(ratios, index=qs)
qs = [0.005, 0.025, 0.165, 0.25, 0.5, 0.75, 0.835, 0.975, 0.995]
level_coefs = {
'id': 0.30, # individual item-store: widest
'item_id': 0.15,
'dept_id': 0.08,
'cat_id': 0.07,
'store_id': 0.08,
'state_id': 0.07,
'total': 0.05, # grand total: narrowest
}
level_ratios = {level: get_ratios(qs, coef) for level, coef in level_coefs.items()}
data-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