Season phase labeling

From wenmin-wu/ds-skills · View interactive version

Season phase labeling is an AI agent skill from the GitHub repository wenmin-wu/ds-skills. Map calendar dates to categorical season phases (offseason, preseason, regular, postseason) using np.select with boundary date conditions

How to use this skill

Skill file

Season Phase Labeling

Overview

Sports, retail, and event-driven datasets exhibit distinct behavioral regimes tied to calendar phases. Mapping each date to its season phase (offseason, preseason, regular season, postseason) creates a powerful categorical feature that captures regime-dependent patterns. Using np.select with ordered conditions and boundary dates handles complex multi-phase calendars cleanly.

Quick Start

import numpy as np

conditions = [
    df["date"] < df["preseason_start"],
    df["date"] < df["regular_start"],
    df["date"] <= df["regular_end"],
    df["date"] < df["postseason_start"],
    df["date"] <= df["postseason_end"],
    df["date"] > df["postseason_end"],
]
labels = ["offseason", "preseason", "regular", "postseason_gap", "postseason", "offseason"]

df["season_phase"] = np.select(conditions, labels, default="unknown")

Workflow

  1. Obtain boundary dates for each phase (from a schedule table or hardcoded per year)
  2. Define ordered conditions — np.select evaluates top-to-bottom, first match wins
  3. Assign phase labels as a new categorical column
  4. Optionally split further (regular season 1st half / 2nd half, all-star break)
  5. Use as a categorical feature in GBDT models or for phase-specific model training

Key Decisions

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.