Files
Airplay-Predictor/docs/MODELS.md
T

92 lines
8.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Models: predicting when an artist gets played again
## How airplay actually happens
The models should follow how stations really decide what to play:
1. **The playlist decides how often.** Each station has a playlist, split into rotation categories. DR publishes them weekly as A / B / C; roughly, A = several plays a day and C = a few a week. Songs are added and dropped weekly.
- DR adds mostly new releases.
- NOVA often adds a song only once it reaches the Spotify Top 50.
2. **The scheduler decides when.** Music-scheduling software places songs into clock slots under separation rules: a minimum gap before the same song or artist repeats, plus dayparting (which hours a song may play).
3. **The rest is outside the lists:** specialist shows, guest DJs, recurrent/gold songs, live sessions. Bauer's exact play logs capture these too.
So the question splits into three:
| Question | Time scale | Data |
|---|---|---|
| Will the song be added to the playlist, and at which station first? | weeks | rotation PDFs, plays across stations |
| While on the list, how often, and when in the day? | hours–days | exact plays |
| When does it drop out (and does it come back as a recurrent)? | weeks–months | plays, DR artist weekly history |
## Methods borrowed from finance and insurance
| Method | Comes from | Used here for |
|---|---|---|
| **Hazard / survival models** (Cox proportional hazards, Weibull, competing risks) | company bankruptcy, credit default, life insurance | how long a song stays in rotation; when it gets dropped (the "default"); being added (the competing event is "never added"). Covariates: station, category, artist history, release age, Spotify chart position. |
| **Hawkes processes** (self-exciting point processes) | trade arrivals, default contagion, earthquake aftershocks | play times: each play raises the short-term rate, and the decay shows the rotation. A multivariate Hawkes model across stations measures spillover: does a P3 play make a P4 or NOVA play more likely? |
| **Inhomogeneous Poisson / renewal processes** with a minimum gap | insurance claims arrivals | inter-play times within a category: a dead time (the separation rule) plus a time-of-day / day-of-week baseline. |
| **Regime switching** (hidden Markov models) | currency regimes, bull/bear markets | a song's lifecycle: not on list → new → A rotation → B/C → recurrent → gone. The weekly rotation lists label the states (for DR) and train the model, which can then infer them for Bauer, where nothing is published. |
| **Claims-frequency GLMs** (Poisson / negative binomial) | car insurance pricing | weekly play counts per song and station, with the overdispersion real data has. |
| **Credibility theory** (Bühlmann / empirical Bayes) | insurance premiums for small portfolios | new or small artists have little history; shrink their estimates towards the station or genre average. |
| **Bass diffusion / lead-lag** (Granger) | product adoption, cross-market lead-lag | how a song spreads from one station to the others, and which stations lead. |
| **State-space / Kalman filter** | volatility, nowcasting | a smooth "airplay momentum" per artist from noisy daily counts. |
## Evaluating predictions
The same way trading models are tested:
- **Walk-forward backtests:** fit on the past, predict the next day or week, roll forward. Never fit on the future.
- **Scores:** log-likelihood of the observed next-play time (probabilistic forecasts, not single numbers), and calibration ("events predicted at 30% happen 30% of the time").
- **Baselines to beat:** "same as last week", and a per-song average rate. A model that can't beat these isn't worth having.
## Order of work
1. **Collect** (done: daily) and **clean**: artist name normalisation across DR and Bauer, featured artists, track ids across stations.
2. **Describe:**
- inter-play distributions per category (they should show the separation gap);
- hour-of-day profiles;
- list lifetimes from DR's 52-week artist histories.
3. **Baselines**, then **survival models** for list lifetime, and **Hawkes / renewal models** for play times.
4. **Cross-station** models once there are a few months of data.
## What is built (src/model)
The first layer follows the design doc's "model we can build now": an **artist × DR channel × week** panel from the DR artist pages (52 Monday–Sunday weeks; the week still running when the pages were read is left out), joined to IFPI chart history by artist name. A chart week counts as known one week after it ends.
```
airplay model panel what the panel holds, rotation thresholds
airplay model backtest [--h 1,4,8] [--refit 1] walk-forward backtest -> docs/BACKTEST.md, backtest_scores
airplay model rank [--h 4] [--max-h 12] [--top 50] the ranking for h = 1..12 -> forecasts
```
- **"In rotation"** = at least τ_c plays in the week. τ_c is the 75th percentile of each channel's non-zero artist-weeks, and at least 3. It is to be recalibrated on the parsed Friday lists.
- **Features** use only what was known at the end of the origin week:
- lagged plays on the channel and on the other channels, and weeks since last played;
- Track Top-40 and Airplay Top-20 status, recency of the latest chart entry, career chart hits;
- from the artist page: Danish, group, gender, career years;
- Christmas, Danish × channel, and channel dummies.
- **Models**, each fitted directly for each horizon h:
- negative binomial for weekly plays (dispersion by maximum likelihood);
- logistic regression for "in rotation";
- a local-level Kalman filter on log plays (the "artist form" first version);
- the doc's persistence and popularity baselines.
- **Backtest:** origins from week 26, refitted weekly. It scores:
- log-loss and Brier score on all rows and on adds (rows not in rotation at the origin);
- PR-AUC on adds and MAE on plays;
- Spearman and NDCG@50 of the artist ranking;
- skill against the baselines, with 90% block-bootstrap intervals;
- calibration by decile.
- **Ranking:** NB means per channel, simulated with one gamma draw per artist shared by all channels. It gives P(rotation) per channel, P(any channel), and total plays with an 80% interval.
**Known limits:**
- **The artist pool is selected.** Only artists heard on DR in the week the pages were read are in it, so every artist was played at the end of the window, and add rates late in the window are inflated. Widening the pool fixes this: artists from IFPI charts, Bauer logs, featured artists and older plays.
- **Not conditioned on a release yet.** The ranking is expected airplay given current form. The release-effect event study needs release dates (Deezer backfill).
- **"Release timing only" is not scored yet.** That baseline needs release dates too.
- **Christmas is barely seen.** It appears only as lag history (weeks 48–52 of 2025), never as a target week.
## Update 15 Nov 2026: new adds, rotation lists, IFPI test bed
- **New adds** (`airplay model adds`, docs/BACKTEST-ADDS.md). The ranking used to show P(artist at or above the play threshold), which is close to 100% for anyone with a current hit. It now shows the chance of a **new add**: entering rotation after at least 4 weeks out, per channel, and on any DR channel after 4 weeks out everywhere, within an 8-week window starting h = 0–12 weeks ahead. Artist-level counts can't tell a new song from an old one returning. But in a week of song-level plays only 3–12% of artists in rotation had two songs in rotation at once, so "drop out, then get added" is the usual pattern. Features include run length on the list and how close the artist is to the threshold.
- **Rotation lists** (`airplay rotations [--wayback] [--reparse]`, src/rotations.rs). Parses DR's PDF from glyph positions, with category headers, columns and the P3 summary page; decoration (rotated text) is dropped. Each page's channel comes from where its artists are played. Old lists came from the Wayback Machine's copies of DR's rotation page, giving **29 weekly lists from May 2023 to Nov 2026** in `rotation_lists`.
- **Thresholds from the lists** (`airplay model calibrate`, docs/CALIBRATION.md). The six lists inside the DR window put "in rotation" at P3 23, P4 13–15, P5 10, P6 16 and P8 7 plays a week, about three times the old play-distribution guess. Every model now uses these.
- **IFPI test bed** (`airplay model ifpi`, docs/IFPI.md): routes and lead–lag per chart period, and a 2010–2026 walk-forward test of Track Top-40 entry → Airplay Top-20 within 8 weeks.