skills/timeseries/prediction-smoothing-lpf/SKILL.md
Applies rolling mean or Butterworth low-pass filter to model predictions for temporal consistency and noise reduction.
npx skillsauth add wenmin-wu/ds-skills timeseries-prediction-smoothing-lpfInstall 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.
Raw per-timestep predictions from classifiers are noisy — consecutive timesteps may flip between classes. Smooth predictions with a rolling mean or Butterworth low-pass filter before event detection. After filtering, rescale by the RMSE ratio (before/after) to preserve signal energy and calibration.
import numpy as np
from scipy import signal
def rolling_smooth(predictions, window):
"""Simple rolling mean smoothing."""
kernel = np.ones(window) / window
return np.convolve(predictions, kernel, mode='same')
def butterworth_smooth(predictions, sample_rate, cutoff_freq, n_passes=3):
"""Butterworth low-pass filter with energy preservation.
Args:
predictions: 1D array of per-timestep scores
sample_rate: samples per day (e.g., 12*60*24 for 5-sec intervals)
cutoff_freq: cutoff in cycles per day (e.g., 60 for ~24-min period)
n_passes: number of filtfilt passes for sharper rolloff
"""
nyquist = sample_rate / 2.0
b, a = signal.butter(1, cutoff_freq / nyquist, btype='low')
before_energy = np.sqrt(np.mean(predictions**2))
smoothed = predictions.copy()
for _ in range(n_passes):
smoothed = signal.filtfilt(b, a, smoothed)
after_energy = np.sqrt(np.mean(smoothed**2))
# Rescale to preserve energy
if after_energy > 0:
smoothed *= before_energy / after_energy
return smoothed
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