skills/tabular/cyclical-feature-encoding/SKILL.md
Encodes cyclical features (hour, month, day-of-week) using sine/cosine transforms to preserve circular distance.
npx skillsauth add wenmin-wu/ds-skills tabular-cyclical-feature-encodingInstall 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.
Features like hour-of-day or month wrap around (23→0, Dec→Jan). Standard ordinal encoding creates a false distance between the endpoints. Sine/cosine transforms map cyclical features onto a unit circle, preserving the true circular distance between values.
import numpy as np
def cyclical_encode(values, period):
"""Encode cyclical feature using sin/cos pair.
Args:
values: array of numeric values (e.g., hours 0-23)
period: full cycle length (24 for hours, 12 for months, 7 for weekdays)
"""
sin = np.sin(2 * np.pi * values / period)
cos = np.cos(2 * np.pi * values / period)
return sin, cos
# Usage
df['hour_sin'], df['hour_cos'] = cyclical_encode(df['hour'], 24)
df['month_sin'], df['month_cos'] = cyclical_encode(df['month'], 12)
df['dow_sin'], df['dow_cos'] = cyclical_encode(df['dayofweek'], 7)
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