skills/timeseries/event-peak-detection/SKILL.md
Detects discrete events (state transitions) from continuous predictions using local maxima with minimum-interval constraints.
npx skillsauth add wenmin-wu/ds-skills timeseries-event-peak-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.
Convert continuous per-timestep predictions into discrete event detections by finding local maxima. Enforce a minimum interval between events to prevent spurious detections. Rank candidates by score and select the top-k based on expected event count (e.g., one onset/wakeup per day). Works with any per-class probability output.
import numpy as np
from scipy.signal import argrelmax
def detect_events(predictions, min_interval, expected_per_day, n_days):
"""Detect events as local maxima in prediction signal.
Args:
predictions: array of shape (T, n_classes), per-timestep probabilities
min_interval: minimum steps between events (e.g., 12*60*6 for 6 hours)
expected_per_day: expected events per day per class
n_days: total days in the series
"""
events = {}
for cls in range(predictions.shape[1]):
# Method 1: scipy argrelmax (fast, clean)
peaks = argrelmax(predictions[:, cls], order=min_interval)[0]
# Method 2: manual local max (more control)
scores = np.zeros(len(predictions))
for i in range(len(predictions)):
window = predictions[max(0, i - min_interval):i + min_interval, cls]
if predictions[i, cls] == window.max():
scores[i] = predictions[i, cls]
# Select top candidates by expected count
n_events = max(1, round(expected_per_day * n_days))
top_indices = np.argsort(scores)[-n_events:]
events[cls] = sorted(top_indices)
return events
argrelmax(order=min_interval) or manual scandata-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