skills/timeseries/retroactive-outlier-rescaling/SKILL.md
Walk backward through a time series and multiplicatively rescale segments when jumps exceed a fraction of the running mean to correct data collection anomalies
npx skillsauth add wenmin-wu/ds-skills timeseries-retroactive-outlier-rescalingInstall 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.
Administrative time series (business counts, registrations, economic indicators) sometimes contain abrupt level shifts caused by data collection changes rather than real trends. Walking backward from the most recent value and rescaling earlier segments when the jump exceeds a threshold (e.g., 20% of running mean) corrects these artifacts while preserving genuine trends.
import numpy as np
def fix_outliers(series, threshold_frac=0.20):
values = series.values.copy().astype(float)
n = len(values)
for i in range(n - 2, -1, -1):
running_mean = np.mean(values[i + 1 : min(i + 4, n)])
if running_mean == 0:
continue
jump = abs(values[i] - values[i + 1])
if jump > threshold_frac * running_mean:
scale = values[i + 1] / values[i] if values[i] != 0 else 1.0
values[: i + 1] *= scale
return values
df["value_clean"] = df.groupby("entity_id")["value"].transform(fix_outliers)
|value[i] - value[i+1]| exceeds threshold_frac * running_mean, compute scale factorvalue[i+1] / value[i]data-ai
Scaled Pinball Loss (SPL) metric for evaluating quantile forecasts, normalized by mean absolute successive differences of training data
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
testing
Use scipy periodogram to identify dominant seasonal frequencies in a time series before selecting Fourier feature orders or ARIMA seasonal parameters