skills/timeseries/density-to-count-roundtrip/SKILL.md
Convert a density metric back to integer counts using known population, round to nearest integer, then recompute density to exploit the discrete nature of the target
npx skillsauth add wenmin-wu/ds-skills timeseries-density-to-count-roundtripInstall 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 target variable is a ratio (count / population), the true underlying quantity is an integer count. Predictions that ignore this produce values on a continuous scale that can never exactly match the true density. Converting predicted density to integer count via the known population denominator, rounding, and converting back snaps predictions to the set of possible true values — often improving SMAPE by 0.001-0.01.
import numpy as np
def roundtrip(predicted_density, population):
count = predicted_density * population / 100 # density is per 100 people
count_rounded = np.round(count).astype(int)
count_rounded = np.maximum(count_rounded, 0)
return count_rounded / population * 100
df["pred_snapped"] = roundtrip(df["pred_density"], df["population"])
count = density * population / scale_factorsnapped_density = rounded_count / population * scale_factorround() (nearest) outperforms floor() or ceil() in expectationdata-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