skills/timeseries/activity-threshold-lastval-fallback/SKILL.md
Override model predictions with last known value for low-activity or low-density entities where learned trends are unreliable
npx skillsauth add wenmin-wu/ds-skills timeseries-activity-threshold-lastval-fallbackInstall 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 entity-level forecasting, some entities have very low counts or near-zero activity. Models trained on the full population tend to hallucinate trends for these entities, producing predictions worse than simply carrying forward the last observed value. Setting an activity threshold and falling back to last-value carry-forward for entities below it improves overall accuracy.
def apply_fallback(df, pred_col, value_col, entity_col, threshold=3.0):
last_values = df.groupby(entity_col)[value_col].last()
entity_mean = df.groupby(entity_col)[value_col].mean()
low_activity = entity_mean[entity_mean < threshold].index
df.loc[df[entity_col].isin(low_activity), pred_col] = (
df.loc[df[entity_col].isin(low_activity), entity_col].map(last_values)
)
return df
df = apply_fallback(df, "prediction", "microbusiness_density", "cfips", threshold=3.0)
alpha * model_pred + (1-alpha) * last_value near the threshold boundarydata-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