skills/timeseries/ratio-target-for-smape/SKILL.md
Transform forecasting target to next/current ratio minus one so that optimizing MAE or squared error implicitly minimizes SMAPE
npx skillsauth add wenmin-wu/ds-skills timeseries-ratio-target-for-smapeInstall 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.
When the evaluation metric is SMAPE, predicting absolute values penalizes errors asymmetrically. Transforming the target to y_{t+1}/y_t - 1 (the relative change) aligns standard regression losses with SMAPE's symmetric percentage nature. The model learns relative changes, then predictions are converted back via pred * last_known_value + last_known_value.
import pandas as pd
df = df.sort_values(["entity_id", "date"])
df["target_ratio"] = df.groupby("entity_id")["value"].transform(
lambda s: s.shift(-1) / s - 1
)
# Train model on target_ratio with standard MAE/MSE loss
# At inference:
last_known = df.groupby("entity_id")["value"].last()
df["prediction"] = last_known * (1 + predicted_ratio)
value_{t+1} / value_t - 1 as the training targetdata-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
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