Long model: sustained-add target (blips were 58% of adds), sanity-check notes
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+85
-65
@@ -1,80 +1,100 @@
|
||||
# The long any-DR model (2019–)
|
||||
|
||||
Total DR plays per artist and week (all channels, P4 regions included). An *add* is τ = 20 or more plays in a week of the next 2 week(s) after 8 weeks under τ. Archive era 2019-04-08 to 2025-11-10 (15538 artists observed, 1040482 qualifying rows, 4681 adds); current panel 2025-11-17 to 2026-11-02 (315968 rows, 1229 adds).
|
||||
Total DR plays per artist and week (all channels, P4 regions included). An *add* is τ = 20 or more plays in a week of the next 2 week(s) after 8 weeks under τ, and τ again in at least 2 of the 3 weeks after it (it stays on). Archive era 2019-04-08 to 2024-09-09 (15538 artists observed, 979721 qualifying rows, 1432 adds); current panel 2025-11-17 to 2026-11-02 (293252 rows, 293 adds).
|
||||
|
||||
Models: **1-year** trains on the 52 weeks of origins before the test period (what the site can do from the current panel alone); **all years** on every earlier origin; **+ older history** adds four features from the artist's weeks before the last 52 (for today's predictions: the 2019–24 archive); **all years + era** adds an archive-era dummy, switched off when predicting (the archive over-represents popular artists, so its base rate is higher). Training rows end `win` weeks before the test origins, so no label is seen early. Δ < 0 means better than 1-year.
|
||||
Models: **1-year** trains on the 52 weeks of origins before the test period (what the site can do from the current panel alone); **all years** on every earlier origin; **+ older history** adds four features from the artist's weeks before the last 52 (for today's predictions: the 2019–24 archive); **all years + era** adds an archive-era dummy, switched off when predicting (the archive over-represents popular artists, so its base rate is higher). Training rows' labels (window plus the weeks checked after it) end before the first test origin, so no label is seen early. Δ < 0 means better than 1-year.
|
||||
|
||||
## Findings (2026-11-17)
|
||||
## Sanity check (2026-11-17)
|
||||
|
||||
- **Training on more years doesn't improve the model.** 2019–2024 vs. the last 52 weeks makes ±0.0003 difference in log loss in every test year and for the current panel, with the same average precision. τ = 50 gives the same picture. A model with ~30 coefficients is already pinned down by one year (300k rows, ~1,200 adds).
|
||||
- **An artist's older history doesn't help today's predictions either.** The four "older history" features (archive 2019–24 for today's origins) gain at most 0.0001.
|
||||
- **Pooling with the archive hurts calibration today** (mean p 0.0051 vs a rate of 0.0037), even with an era dummy. The archive over-represents artists whose pages got crawled.
|
||||
- **So the one-year limit isn't what holds the model back.** Signal is: there's little to learn about *when* an artist crosses into heavy rotation beyond their current trajectory, releases, NMF and charts. Better data on upcoming releases and promo (singles sent to radio) is more promising than more history.
|
||||
The first version of this report counted any week at τ as an add. Checking the current panel showed most of those were blips:
|
||||
- The typical "add" at τ = 20 was 2 plays on national P4, repeated on each regional station.
|
||||
- 58% fell back under τ in each of the next 4 weeks; at τ = 50 it was 56%.
|
||||
|
||||
The target now requires the artist to stay on: τ again in at least 2 of the 3 weeks after. Training labels end before the first test origin, including those 3 weeks.
|
||||
|
||||
Other checks:
|
||||
- **Archive pages that list only weeks with plays** (13,277 captures) look genuine. They're new or rare artists, e.g. a debut going 1 → 17 → 45 plays. So unlisted weeks are counted as 0 plays.
|
||||
- **Scale between the periods:** the archive's weekly totals match the current panel *with* P4 regions summed (99th percentile 136 vs 213, against 45 without the regions). The archive runs somewhat lower, which the era dummy absorbs.
|
||||
- **Leaks:** features only use weeks up to t, except the release and New Music Friday flags for the window. Those are scenario inputs, as on the site. Chart positions use the chart published a week before t.
|
||||
- **Known biases:**
|
||||
- Discographies (Deezer) and NMF Denmark lookups exist only for today's pool, so in the archive the "discography known" and release flags favour artists who were still played in 2025–26. That flatters the archive years; it doesn't change the comparison within a year.
|
||||
- The archive also over-represents artists whose pages got crawled.
|
||||
- Chart matching here uses primary names only (the site also uses aliases).
|
||||
- **Power:** the current-panel test has 132 sustained adds. The log-loss intervals rule out gains larger than about 3–5% of log loss. Differences in average precision (0.035–0.046) are within noise.
|
||||
- **Skill:** adds are rare (0.09–0.25% of rows). An average precision of 0.04–0.19 ranks real adds 40–75 times better than chance, though Brier skill stays near zero.
|
||||
|
||||
## Findings
|
||||
|
||||
- With sustained adds, *all years* beats *1-year* on the current panel by 0.0001 in log loss (90% CI −0.0003 to −0.0001, about 2%). But it's worse calibrated (mean p 0.0011 vs a rate of 0.0009) and has lower Brier skill.
|
||||
- In the archive years it's a wash: −0.0002 in 2023, +0.0002 in 2024, 0 elsewhere.
|
||||
- Older-history features: within ±0.0001 for today.
|
||||
- τ = 50 shows the same: no reliable gain.
|
||||
- **More years and older history help little or not at all.** The one-year limit is not the bottleneck; better release and promo timing is the more promising lever.
|
||||
|
||||
## Out of sample
|
||||
|
||||
| test period | rows | adds | model | log loss | Brier skill | avg precision | mean p / rate | Δ log loss vs 1-year (90% CI) |
|
||||
|---|---|---|---|---|---|---|---|---|
|
||||
| 2021 | 342367 | 1605 | 1-year | 0.0219 | +0.062 | 0.110 | 0.0038 / 0.0047 | — |
|
||||
| 2021 | 342367 | 1605 | all years | 0.0219 | +0.061 | 0.108 | 0.0038 / 0.0047 | +0.0001 (+0.0000 to +0.0001) |
|
||||
| 2021 | 342367 | 1605 | all years + era | 0.0219 | +0.061 | 0.108 | 0.0038 / 0.0047 | +0.0001 (+0.0000 to +0.0001) |
|
||||
| 2021 | 342367 | 1605 | 1-year + older history | 0.0221 | +0.059 | 0.106 | 0.0034 / 0.0047 | +0.0002 (+0.0001 to +0.0004) |
|
||||
| 2021 | 342367 | 1605 | all years + era + older history | 0.0222 | +0.058 | 0.105 | 0.0034 / 0.0047 | +0.0003 (+0.0002 to +0.0004) |
|
||||
| 2022 | 146672 | 1098 | 1-year | 0.0329 | +0.042 | 0.109 | 0.0088 / 0.0075 | — |
|
||||
| 2022 | 146672 | 1098 | all years | 0.0330 | +0.049 | 0.108 | 0.0077 / 0.0075 | +0.0001 (-0.0002 to +0.0004) |
|
||||
| 2022 | 146672 | 1098 | all years + era | 0.0330 | +0.049 | 0.108 | 0.0077 / 0.0075 | +0.0001 (-0.0002 to +0.0004) |
|
||||
| 2022 | 146672 | 1098 | 1-year + older history | 0.0329 | +0.045 | 0.111 | 0.0087 / 0.0075 | -0.0001 (-0.0001 to -0.0000) |
|
||||
| 2022 | 146672 | 1098 | all years + era + older history | 0.0329 | +0.050 | 0.109 | 0.0080 / 0.0075 | -0.0000 (-0.0003 to +0.0003) |
|
||||
| 2023 | 134721 | 549 | 1-year | 0.0195 | +0.043 | 0.111 | 0.0062 / 0.0041 | — |
|
||||
| 2023 | 134721 | 549 | all years | 0.0193 | +0.040 | 0.111 | 0.0061 / 0.0041 | -0.0002 (-0.0003 to +0.0001) |
|
||||
| 2023 | 134721 | 549 | all years + era | 0.0193 | +0.040 | 0.111 | 0.0061 / 0.0041 | -0.0002 (-0.0003 to +0.0001) |
|
||||
| 2023 | 134721 | 549 | 1-year + older history | 0.0197 | +0.033 | 0.099 | 0.0064 / 0.0041 | +0.0002 (+0.0001 to +0.0003) |
|
||||
| 2023 | 134721 | 549 | all years + era + older history | 0.0194 | +0.036 | 0.101 | 0.0061 / 0.0041 | -0.0001 (-0.0002 to +0.0002) |
|
||||
| 2024 | 20378 | 107 | 1-year | 0.0220 | +0.097 | 0.179 | 0.0055 / 0.0053 | — |
|
||||
| 2024 | 20378 | 107 | all years | 0.0223 | +0.095 | 0.179 | 0.0067 / 0.0053 | +0.0003 (+0.0001 to +0.0009) |
|
||||
| 2024 | 20378 | 107 | all years + era | 0.0223 | +0.095 | 0.179 | 0.0067 / 0.0053 | +0.0003 (+0.0001 to +0.0009) |
|
||||
| 2024 | 20378 | 107 | 1-year + older history | 0.0218 | +0.101 | 0.186 | 0.0056 / 0.0053 | -0.0002 (-0.0004 to -0.0001) |
|
||||
| 2024 | 20378 | 107 | all years + era + older history | 0.0225 | +0.088 | 0.164 | 0.0066 / 0.0053 | +0.0005 (+0.0003 to +0.0010) |
|
||||
| current panel, origins from 2026-05-18 | 173697 | 641 | 1-year | 0.0163 | +0.069 | 0.128 | 0.0034 / 0.0037 | — |
|
||||
| current panel, origins from 2026-05-18 | 173697 | 641 | all years | 0.0164 | +0.072 | 0.125 | 0.0037 / 0.0037 | +0.0001 (-0.0000 to +0.0002) |
|
||||
| current panel, origins from 2026-05-18 | 173697 | 641 | all years + era | 0.0166 | +0.065 | 0.126 | 0.0051 / 0.0037 | +0.0003 (+0.0001 to +0.0005) |
|
||||
| current panel, origins from 2026-05-18 | 173697 | 641 | 1-year + older history | 0.0162 | +0.069 | 0.129 | 0.0033 / 0.0037 | -0.0000 (-0.0001 to +0.0001) |
|
||||
| current panel, origins from 2026-05-18 | 173697 | 641 | all years + era + older history | 0.0164 | +0.065 | 0.126 | 0.0048 / 0.0037 | +0.0002 (-0.0000 to +0.0003) |
|
||||
| 2021 | 314613 | 392 | 1-year | 0.0072 | +0.012 | 0.054 | 0.0018 / 0.0012 | — |
|
||||
| 2021 | 314613 | 392 | all years | 0.0072 | +0.008 | 0.053 | 0.0018 / 0.0012 | +0.0000 (+0.0000 to +0.0000) |
|
||||
| 2021 | 314613 | 392 | all years + era | 0.0072 | +0.008 | 0.053 | 0.0018 / 0.0012 | +0.0000 (+0.0000 to +0.0000) |
|
||||
| 2021 | 314613 | 392 | 1-year + older history | 0.0071 | +0.024 | 0.054 | 0.0014 / 0.0012 | -0.0001 (-0.0002 to -0.0000) |
|
||||
| 2021 | 314613 | 392 | all years + era + older history | 0.0071 | +0.021 | 0.053 | 0.0014 / 0.0012 | -0.0001 (-0.0002 to -0.0000) |
|
||||
| 2022 | 135465 | 263 | 1-year | 0.0108 | +0.004 | 0.050 | 0.0022 / 0.0019 | — |
|
||||
| 2022 | 135465 | 263 | all years | 0.0108 | +0.015 | 0.051 | 0.0024 / 0.0019 | +0.0000 (-0.0002 to +0.0001) |
|
||||
| 2022 | 135465 | 263 | all years + era | 0.0108 | +0.015 | 0.051 | 0.0024 / 0.0019 | +0.0000 (-0.0002 to +0.0001) |
|
||||
| 2022 | 135465 | 263 | 1-year + older history | 0.0108 | -0.015 | 0.048 | 0.0022 / 0.0019 | -0.0000 (-0.0002 to +0.0001) |
|
||||
| 2022 | 135465 | 263 | all years + era + older history | 0.0107 | +0.013 | 0.049 | 0.0021 / 0.0019 | -0.0001 (-0.0003 to +0.0000) |
|
||||
| 2023 | 126845 | 204 | 1-year | 0.0079 | +0.056 | 0.106 | 0.0015 / 0.0016 | — |
|
||||
| 2023 | 126845 | 204 | all years | 0.0077 | +0.069 | 0.124 | 0.0015 / 0.0016 | -0.0002 (-0.0003 to -0.0000) |
|
||||
| 2023 | 126845 | 204 | all years + era | 0.0077 | +0.069 | 0.124 | 0.0015 / 0.0016 | -0.0002 (-0.0003 to -0.0000) |
|
||||
| 2023 | 126845 | 204 | 1-year + older history | 0.0078 | +0.059 | 0.108 | 0.0017 / 0.0016 | -0.0001 (-0.0002 to +0.0000) |
|
||||
| 2023 | 126845 | 204 | all years + era + older history | 0.0077 | +0.067 | 0.118 | 0.0016 / 0.0016 | -0.0002 (-0.0003 to +0.0000) |
|
||||
| 2024 | 16092 | 41 | 1-year | 0.0116 | +0.090 | 0.185 | 0.0026 / 0.0025 | — |
|
||||
| 2024 | 16092 | 41 | all years | 0.0118 | +0.057 | 0.148 | 0.0026 / 0.0025 | +0.0002 (+0.0001 to +0.0011) |
|
||||
| 2024 | 16092 | 41 | all years + era | 0.0118 | +0.057 | 0.148 | 0.0026 / 0.0025 | +0.0002 (+0.0001 to +0.0011) |
|
||||
| 2024 | 16092 | 41 | 1-year + older history | 0.0114 | +0.082 | 0.169 | 0.0028 / 0.0025 | -0.0003 (-0.0006 to +0.0000) |
|
||||
| 2024 | 16092 | 41 | all years + era + older history | 0.0118 | +0.055 | 0.135 | 0.0028 / 0.0025 | +0.0002 (+0.0002 to +0.0010) |
|
||||
| current panel, origins from 2026-05-18 | 150981 | 132 | 1-year | 0.0053 | +0.012 | 0.038 | 0.0007 / 0.0009 | — |
|
||||
| current panel, origins from 2026-05-18 | 150981 | 132 | all years | 0.0052 | +0.003 | 0.046 | 0.0011 / 0.0009 | -0.0001 (-0.0003 to -0.0001) |
|
||||
| current panel, origins from 2026-05-18 | 150981 | 132 | all years + era | 0.0053 | -0.005 | 0.046 | 0.0013 / 0.0009 | -0.0000 (-0.0002 to -0.0001) |
|
||||
| current panel, origins from 2026-05-18 | 150981 | 132 | 1-year + older history | 0.0053 | +0.007 | 0.035 | 0.0007 / 0.0009 | -0.0000 (-0.0000 to +0.0000) |
|
||||
| current panel, origins from 2026-05-18 | 150981 | 132 | all years + era + older history | 0.0054 | -0.027 | 0.046 | 0.0016 / 0.0009 | +0.0001 (-0.0002 to +0.0000) |
|
||||
|
||||
## Coefficients (all years + era + older history, every row)
|
||||
|
||||
| feature | β |
|
||||
|---|---|
|
||||
| intercept | -7.944 |
|
||||
| log plays week t | +0.720 |
|
||||
| log mean plays last 4w | +0.329 |
|
||||
| log mean plays last 12w | +1.063 |
|
||||
| log max weekly plays last 52w | +0.583 |
|
||||
| on DR 9-25 weeks ago | +0.434 |
|
||||
| on DR 26-52 weeks ago | -0.122 |
|
||||
| weeks observed of last 52 (share) | +0.364 |
|
||||
| weeks with plays of last 12 (share) | -2.339 |
|
||||
| trend: last 4w vs the 8 before | +0.511 |
|
||||
| discography known | +0.256 |
|
||||
| release in last 4w | +0.405 |
|
||||
| release 5-12w ago | +0.187 |
|
||||
| release in the window | +0.381 |
|
||||
| log releases last 52w | -0.163 |
|
||||
| on Track Top-40 now | +0.587 |
|
||||
| on Airplay Top-20 now | +0.546 |
|
||||
| log Top-40 hits so far | +0.035 |
|
||||
| log Airplay hits so far | +0.094 |
|
||||
| new chart entry in last 4w | +0.078 |
|
||||
| NMF data covers t | -0.397 |
|
||||
| NMF Denmark in last 4w | +0.920 |
|
||||
| NMF Denmark in the window | +1.103 |
|
||||
| log NMF placements last 52w | -0.274 |
|
||||
| Danish | +0.065 |
|
||||
| group | +0.099 |
|
||||
| female | +0.284 |
|
||||
| season index of the window | +0.019 |
|
||||
| archive era | -0.204 |
|
||||
| older history: observed before the last 52w | +0.226 |
|
||||
| older history: log max weekly plays | -0.034 |
|
||||
| older history: log adds | +0.276 |
|
||||
| older history: share of weeks on DR | -1.115 |
|
||||
| intercept | -9.607 |
|
||||
| log plays week t | +1.493 |
|
||||
| log mean plays last 4w | -0.240 |
|
||||
| log mean plays last 12w | +0.653 |
|
||||
| log max weekly plays last 52w | +0.333 |
|
||||
| on DR 9-25 weeks ago | +0.323 |
|
||||
| on DR 26-52 weeks ago | +0.159 |
|
||||
| weeks observed of last 52 (share) | +1.014 |
|
||||
| weeks with plays of last 12 (share) | -1.882 |
|
||||
| trend: last 4w vs the 8 before | +0.506 |
|
||||
| discography known | +0.577 |
|
||||
| release in last 4w | +0.692 |
|
||||
| release 5-12w ago | +0.294 |
|
||||
| release in the window | +0.638 |
|
||||
| log releases last 52w | -0.169 |
|
||||
| on Track Top-40 now | +0.783 |
|
||||
| on Airplay Top-20 now | +0.887 |
|
||||
| log Top-40 hits so far | -0.059 |
|
||||
| log Airplay hits so far | +0.246 |
|
||||
| new chart entry in last 4w | +0.500 |
|
||||
| NMF data covers t | -0.420 |
|
||||
| NMF Denmark in last 4w | +1.052 |
|
||||
| NMF Denmark in the window | +1.587 |
|
||||
| log NMF placements last 52w | -0.150 |
|
||||
| Danish | +0.451 |
|
||||
| group | +0.207 |
|
||||
| female | +0.602 |
|
||||
| season index of the window | +1.000 |
|
||||
| archive era | -0.032 |
|
||||
| older history: observed before the last 52w | -0.666 |
|
||||
| older history: log max weekly plays | +0.040 |
|
||||
| older history: log adds | +0.192 |
|
||||
| older history: share of weeks on DR | -0.265 |
|
||||
|
||||
+28
-21
@@ -37,6 +37,8 @@ pub struct Long {
|
||||
releases: Vec<Option<Vec<NaiveDate>>>,
|
||||
nmf: Vec<Vec<(NaiveDate, Option<i64>)>>,
|
||||
season: [f64; 54],
|
||||
/// Weeks after the add that the label looks at (see `label`).
|
||||
pub stay: usize,
|
||||
}
|
||||
|
||||
impl Long {
|
||||
@@ -104,18 +106,21 @@ impl Long {
|
||||
let chart = chart_states(db, &weeks, &names, na)?;
|
||||
let releases = load_releases(db, &id_of, na)?;
|
||||
let nmf = load_nmf_dk(db, &id_of, &artists)?;
|
||||
Ok(Long { weeks, artists, y, obs, cur0, known, chart, releases, nmf, season: p.season })
|
||||
Ok(Long { weeks, artists, y, obs, cur0, known, chart, releases, nmf, season: p.season, stay: 3 })
|
||||
}
|
||||
|
||||
/// Does origin (a, t) qualify, and if so was there an add in the window?
|
||||
fn label(&self, a: usize, t: usize, win: usize, tau: f64) -> Option<bool> {
|
||||
if t + 1 < OFF || t + win >= self.w() { return None; }
|
||||
let end = t + win + self.stay;
|
||||
if t + 1 < OFF || end >= self.w() { return None; }
|
||||
if t >= self.cur0 && self.known[a] > t { return None; }
|
||||
// Don't let a window straddle the gap between the eras.
|
||||
if t < self.cur0 && t + win >= self.cur0 { return None; }
|
||||
if !(t + 1 - OFF..=t + win).all(|w| self.obs(a, w)) { return None; }
|
||||
if t < self.cur0 && end >= self.cur0 { return None; }
|
||||
if !(t + 1 - OFF..=end).all(|w| self.obs(a, w)) { return None; }
|
||||
if (t + 1 - OFF..=t).any(|w| self.y(a, w) >= tau) { return None; }
|
||||
Some((t + 1..=t + win).any(|w| self.y(a, w) >= tau))
|
||||
// stay = 0: any week at τ (a blip counts). stay = k: and τ again in at least 2 of the k weeks after it.
|
||||
let on = |w: usize| self.y(a, w) >= tau;
|
||||
Some((t + 1..=t + win).any(|w| on(w) && (self.stay == 0 || (w + 1..=w + self.stay).filter(|&v| on(v)).count() >= 2.min(self.stay))))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,20 +272,22 @@ fn boot(te: &Test, m: usize, base: usize) -> (f64, f64, f64) {
|
||||
(d, v[50], v[949])
|
||||
}
|
||||
|
||||
pub fn run(db: &Db, p: &Panel, tau: f64, win: usize) -> Result<String> {
|
||||
let l = Long::load(db, p)?;
|
||||
pub fn run(db: &Db, p: &Panel, tau: f64, win: usize, stay: usize) -> Result<String> {
|
||||
let mut l = Long::load(db, p)?;
|
||||
l.stay = stay;
|
||||
let all = rows(&l, win, tau);
|
||||
let mut md = String::new();
|
||||
let n_old = all.iter().filter(|r| r.0 < l.cur0).count();
|
||||
let a_old = all.iter().filter(|r| r.0 < l.cur0 && r.2).count();
|
||||
let _ = writeln!(md, "# The long any-DR model (2019–)\n");
|
||||
let _ = writeln!(md, "Total DR plays per artist and week (all channels, P4 regions included). An *add* is τ = {tau} or more plays in a week of the next {win} week(s) after {OFF} weeks under τ. \
|
||||
let _ = writeln!(md, "Total DR plays per artist and week (all channels, P4 regions included). An *add* is τ = {tau} or more plays in a week of the next {win} week(s) after {OFF} weeks under τ{}. \
|
||||
Archive era {} to {} ({} artists observed, {} qualifying rows, {} adds); current panel {} to {} ({} rows, {} adds).\n",
|
||||
l.weeks[0], l.weeks[l.cur0 - 1], (0..l.artists.len()).filter(|&a| (0..l.cur0).any(|w| l.obs(a, w))).count(), n_old, a_old,
|
||||
if stay > 0 { format!(", and τ again in at least 2 of the {stay} weeks after it (it stays on)") } else { " (a one-week blip counts)".into() },
|
||||
l.weeks[0], l.weeks[(0..l.cur0).rev().find(|&w| (0..l.artists.len()).any(|a| l.obs(a, w))).unwrap_or(0)], (0..l.artists.len()).filter(|&a| (0..l.cur0).any(|w| l.obs(a, w))).count(), n_old, a_old,
|
||||
l.weeks[l.cur0], l.weeks[l.w() - 1], all.len() - n_old, all.iter().filter(|r| r.0 >= l.cur0 && r.2).count());
|
||||
let _ = writeln!(md, "Models: **1-year** trains on the 52 weeks of origins before the test period (what the site can do from the current panel alone); \
|
||||
**all years** on every earlier origin; **+ older history** adds four features from the artist's weeks before the last 52 (for today's predictions: the 2019–24 archive); **all years + era** adds an archive-era dummy, switched off when predicting (the archive over-represents popular artists, so its base rate is higher). \
|
||||
Training rows end `win` weeks before the test origins, so no label is seen early. Δ < 0 means better than 1-year.\n");
|
||||
Training rows' labels (window plus the weeks checked after it) end before the first test origin, so no label is seen early. Δ < 0 means better than 1-year.\n");
|
||||
|
||||
let models = ["1-year", "all years", "all years + era", "1-year + older history", "all years + era + older history"];
|
||||
let mut tests = Vec::new();
|
||||
@@ -292,11 +299,11 @@ pub fn run(db: &Db, p: &Panel, tau: f64, win: usize) -> Result<String> {
|
||||
let test: Vec<&(usize, usize, bool)> = all.iter().filter(|r| l.weeks[r.0] >= s && l.weeks[r.0] < e && r.0 < l.cur0).collect();
|
||||
if test.iter().filter(|r| r.2).count() < 20 { continue; }
|
||||
let fits = [
|
||||
Fit::new(&l, &all, |t| t + win < t0 && t + HIST >= t0, win, tau, Opt { era: false, hist: false }),
|
||||
Fit::new(&l, &all, |t| t + win < t0, win, tau, Opt { era: false, hist: false }),
|
||||
Fit::new(&l, &all, |t| t + win < t0, win, tau, Opt { era: true, hist: false }),
|
||||
Fit::new(&l, &all, |t| t + win < t0 && t + HIST >= t0, win, tau, Opt { era: false, hist: true }),
|
||||
Fit::new(&l, &all, |t| t + win < t0, win, tau, Opt { era: true, hist: true }),
|
||||
Fit::new(&l, &all, |t| t + win + l.stay < t0 && t + HIST >= t0, win, tau, Opt { era: false, hist: false }),
|
||||
Fit::new(&l, &all, |t| t + win + l.stay < t0, win, tau, Opt { era: false, hist: false }),
|
||||
Fit::new(&l, &all, |t| t + win + l.stay < t0, win, tau, Opt { era: true, hist: false }),
|
||||
Fit::new(&l, &all, |t| t + win + l.stay < t0 && t + HIST >= t0, win, tau, Opt { era: false, hist: true }),
|
||||
Fit::new(&l, &all, |t| t + win + l.stay < t0, win, tau, Opt { era: true, hist: true }),
|
||||
];
|
||||
tests.push(Test { name: year.to_string(), t: test.iter().map(|r| r.0).collect(), y: test.iter().map(|r| r.2).collect(),
|
||||
p: fits.iter().map(|f| test.iter().map(|r| f.p(&l, r.1, r.0, win, tau)).collect()).collect() });
|
||||
@@ -308,11 +315,11 @@ pub fn run(db: &Db, p: &Panel, tau: f64, win: usize) -> Result<String> {
|
||||
while t0 + win < l.w() {
|
||||
let t1 = (t0 + 4).min(l.w());
|
||||
let fits = [
|
||||
Fit::new(&l, &all, |t| t >= l.cur0 && t + win < t0, win, tau, Opt { era: false, hist: false }),
|
||||
Fit::new(&l, &all, |t| t + win < t0, win, tau, Opt { era: false, hist: false }),
|
||||
Fit::new(&l, &all, |t| t + win < t0, win, tau, Opt { era: true, hist: false }),
|
||||
Fit::new(&l, &all, |t| t >= l.cur0 && t + win < t0, win, tau, Opt { era: false, hist: true }),
|
||||
Fit::new(&l, &all, |t| t + win < t0, win, tau, Opt { era: true, hist: true }),
|
||||
Fit::new(&l, &all, |t| t >= l.cur0 && t + win + l.stay < t0, win, tau, Opt { era: false, hist: false }),
|
||||
Fit::new(&l, &all, |t| t + win + l.stay < t0, win, tau, Opt { era: false, hist: false }),
|
||||
Fit::new(&l, &all, |t| t + win + l.stay < t0, win, tau, Opt { era: true, hist: false }),
|
||||
Fit::new(&l, &all, |t| t >= l.cur0 && t + win + l.stay < t0, win, tau, Opt { era: false, hist: true }),
|
||||
Fit::new(&l, &all, |t| t + win + l.stay < t0, win, tau, Opt { era: true, hist: true }),
|
||||
];
|
||||
for r in all.iter().filter(|r| r.0 >= t0 && r.0 < t1) {
|
||||
cur.t.push(r.0); cur.y.push(r.2);
|
||||
@@ -325,7 +332,7 @@ pub fn run(db: &Db, p: &Panel, tau: f64, win: usize) -> Result<String> {
|
||||
let _ = writeln!(md, "## Out of sample\n");
|
||||
report(&mut md, &models, &tests);
|
||||
|
||||
let f = Fit::new(&l, &all, |t| t + win < l.w(), win, tau, Opt { era: true, hist: true });
|
||||
let f = Fit::new(&l, &all, |t| t + win + l.stay < l.w(), win, tau, Opt { era: true, hist: true });
|
||||
let _ = writeln!(md, "\n## Coefficients (all years + era + older history, every row)\n\n| feature | β |\n|---|---|");
|
||||
for (n, b) in NAMES.iter().zip(&f.b) { let _ = writeln!(md, "| {n} | {b:+.3} |"); }
|
||||
Ok(md)
|
||||
|
||||
+3
-2
@@ -9,7 +9,7 @@
|
||||
//! airplay model ifpi the 20-year IFPI test bed -> docs/IFPI.md
|
||||
//! airplay model events [--out docs/BACKTEST-EVENTS.md] backtest of the release-event model
|
||||
//! airplay model adds [--h 0,4] [--out docs/BACKTEST-ADDS.md] backtest of the new-add model
|
||||
//! airplay model long [--tau 20] [--w 2] [--out docs/LONG.md] 2019– any-DR model, all years vs 1 year
|
||||
//! airplay model long [--tau 20] [--w 2] [--stay 3] [--out docs/LONG.md] 2019– any-DR model, all years vs 1 year
|
||||
//! airplay model rank [--h 4] [--max-h 12] [--top 50]
|
||||
|
||||
pub mod addcheck;
|
||||
@@ -94,7 +94,8 @@ pub fn run(db: &Db, args: &[String]) -> Result<()> {
|
||||
Some("long") => {
|
||||
let tau: f64 = arg(args, "--tau").and_then(|s| s.parse().ok()).unwrap_or(20.0);
|
||||
let win: usize = arg(args, "--w").and_then(|s| s.parse().ok()).unwrap_or(2);
|
||||
let md = long::run(db, &p, tau, win)?;
|
||||
let stay: usize = arg(args, "--stay").and_then(|s| s.parse().ok()).unwrap_or(3);
|
||||
let md = long::run(db, &p, tau, win, stay)?;
|
||||
if let Some(out) = arg(args, "--out") { std::fs::write(out, &md)?; }
|
||||
print!("{md}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user