agentleFS
WalrusQuantWalrusQuant/sports-analytic-skills/skills/time-series-sports/SKILL.md

time-series-sports

Skill54 starsChanged 8 days agoMITView on GitHub

Engineer and compare time-safe sports form features. Use for rolling windows, EWMA, rest, schedule gaps, early-season handling, and chronological evaluation.

  • Installs packages

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 6 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Do not use when:

    line 39
  2. Distinctive:

    Document window/span, shift rule, and min history.

    line 68
  3. Distinctive:

    Read form_feature_recipes.md when implementing rolling, expanding, or EWMA features.

    line 84
  4. Distinctive:

    Use identical expanding folds and the complete cases shared by both feature sets.

    line 106
  5. Distinctive:

    No centered rolling windows that peek forward.

    line 131
  6. Distinctive:

    Document shift rule in every feature card / experiment log.

    line 136

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Time Series & Form (Sports)

Overview

Sports performance is ordered in time. This skill builds form features and simple trajectory forecasts that are legal at decision time T:

  • rolling means
  • expanding rates
  • EWMA / decay
  • rest gaps
  • regime flags

Build shifted EWMA features on a user-owned event table, then compare already-computed feature sets on the same folds.

Non-negotiable: shift (or as-of) so the current game is never inside the feature.


When to Use This Skill

Use when:

  • Team/player form features for pre-game models
  • Rolling averages, EWMA, half-life decay
  • Forecasting next-game stats from trajectories
  • Handling bye weeks, missing games, season breaks
  • Comparing recency-weighted form vs static season averages
  • User says “hot streak,” “last 5,” or “recent form”

Do not use when:

NeedGo instead
Pure cross-sectional comparison with no recencyEDA / stats skills
Opponent-adjusted strength is the real goalalso ratings-strength-models
Static season aggregates already sufficient and time-safesimpler baselines
Feature legality review of a finished matrixleakage-audit

Installation

python -m pip install pandas numpy scikit-learn pyarrow

Build features in the user's environment. This repository does not ship a form-feature program.


Workflow

  1. Define the entity and frequency (team-game, player-game, week).
  2. Sort by entity + time; handle missing games explicitly.
  3. Choose window/decay rules; tune only inside training folds.
  4. Apply shift(1) / as-of so current game is never inside the feature.
  5. Compare form features against static baselines under walk-forward validation.
  6. Watch early-season small-sample explosions — min-games thresholds or shrinkage.
  7. Document window/span, shift rule, and min history.
  8. Hand off to baselines / predictive models / leakage audit.

Core Techniques

TechniqueSports useTime-safety rule
Expanding meanseason-to-date win % / PFshift before expand
Rolling meanlast K games formshift then rolling
EWMArecency-weighted formewm on shifted series
Rest daysschedule gapsdiff of game dates
Season phaseweek number, monthknown pre-game
Regime splitrule changes, coaching erasflag by date known at T

Read form_feature_recipes.md when implementing rolling, expanding, or EWMA features. Read early_season.md when choosing priors, minimum history, or shrinkage. Read rest_and_gaps.md for byes, calendar gaps, and elapsed-time features.


Feature construction

Require non-null entity keys, a parseable time or order field, and numeric or boolean values. Reject infinite values and contradictory event order. Leave missing observations missing. Do not fill them with zero. Shift each value by one event, then apply the rolling or EWMA summary.

Name generated fields so the shift is obvious, for example pre_ewma_points. Group by season when history should not cross the offseason; otherwise say that history carries across seasons. Team files have game_date as a date and no start_time. Convert it with pd.to_datetime before using .dt. Order same-day games with event_time from the data-sources panel (games.start_time). An arbitrary row id is not order.

Opponent features

Compute each participant's history independently, then join the participant and opponent snapshots by stable event/entity keys. Assert that both snapshots were available before the event. Never derive opponent form from the focal row's current result.

Compare feature sets

Use identical expanding folds and the complete cases shared by both feature sets. Validate binary targets and finite numeric features, and do not impute them in the comparison. The comparison evaluates columns that already exist. It does not make an illegal feature legal.

Early-Season Handling

ProblemMitigation
Week 1 empty historyNA features + drop or league prior
Tiny n rolling windowsrequire pre_games_played >= k
Noisy short rollsshrinkage toward league mean / expanding mean
Bye weeksrest_days feature; don’t fill with zeros blindly
Offseason gapsdon’t treat long rest as a normal short-week rest without care

Validation

Form features are hypotheses. Evaluate alternative windows on identical chronological folds, against a static or simpler baseline.

Tune window/span inside training folds only.


Hard Constraints

  1. No centered rolling windows that peek forward.
  2. No “season average including current game.”
  3. Early-season priors/shrinkage when n is tiny.
  4. Validate across seasons, not one hot streak.
  5. Opponent strength still matters — raw form ≠ opponent-adjusted strength (ratings-strength-models).
  6. Document shift rule in every feature card / experiment log.

Anti-Patterns

  • Fixed 5-game mean with no shrinkage
  • Ignoring opponent strength in raw form
  • Treating playoffs and regular season as identical without a flag
  • Tuning window length on the final test season only
  • Filling NA form with 0.0 silently
  • Claiming “hot streak” causality from one rolling mean

Reporting Template

Form model: rolling / EWMA / expanding
Entity/frequency:
Windows/span:
Shift rule: shift(1) before aggregate
Min history:
Validation: vs static baseline under walk-forward
Limits: early season, injuries, opponent strength…
Reproduce:

Output Contract

Done means:

  • Entity/frequency stated
  • Shift/as-of rule stated
  • Window/span documented
  • Min history rule stated
  • Walk-forward comparison planned or done
  • Leakage check planned or done

Worked Example

On a team-game file, sort by team_id and game_date, shift the result, then take an EWMA. Compare that column with a shifted three-game mean under the same season folds before preferring either window.

import pandas as pd
g = pd.read_parquet("team_games.parquet").sort_values(["team_id", "game_date"])
g["pre_points"] = g.groupby("team_id")["score"].shift(1)
g["pre_ewma_points"] = g.groupby("team_id")["pre_points"].transform(
    lambda s: s.ewm(span=5, min_periods=1).mean()
)

References

references/

FileContents
form_feature_recipes.mdshift/roll/expand/EWMA recipes
early_season.mdsmall-sample handling
rest_and_gaps.mdbyes and calendar gaps

Related Skills

NeedSkill
Feature legalityfeature-rules
Ratings (opponent-adjusted)ratings-strength-models
EDAeda-sports
Modelsbaseline-models, predictive-modeling
Leakageleakage-audit

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.