skills/timeseries/periodogram-seasonality-detection/SKILL.md
Use scipy periodogram to identify dominant seasonal frequencies in a time series before selecting Fourier feature orders or ARIMA seasonal parameters
npx skillsauth add wenmin-wu/ds-skills timeseries-periodogram-seasonality-detectionInstall 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.
Before adding seasonal features, determine which frequencies actually exist in the data. The periodogram decomposes a time series into its frequency components, revealing peaks at dominant cycles (weekly, monthly, annual). This avoids overfitting to phantom seasonality and guides the choice of Fourier order or SARIMA seasonal period.
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import periodogram
fs = 365.25 # samples per year (daily data)
freqs, spectrum = periodogram(
series.dropna().values,
fs=fs,
detrend="linear",
window="boxcar",
scaling="spectrum",
)
plt.figure(figsize=(10, 4))
plt.step(freqs, spectrum)
plt.xscale("log")
plt.xlabel("Cycles per year")
plt.ylabel("Power")
plt.axvline(1, color="r", alpha=0.3, label="Annual")
plt.axvline(52, color="g", alpha=0.3, label="Weekly")
plt.legend()
plt.show()
# Find top 3 peaks
top_idx = np.argsort(spectrum)[-3:]
dominant_periods = 1.0 / freqs[top_idx] # in days
scipy.signal.periodogramfs=365.25 (cycles/year), hourly → fs=8766"linear" removes simple trends; for nonstationary data, difference first"boxcar" (no taper) for maximum frequency resolution; "hann" reduces spectral leakagedata-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