Upload folder using huggingface_hub
Browse files- README.md +6 -4
- app.py +138 -29
- predictions/forecasts.parquet +2 -2
- predictions/history.parquet +2 -2
- predictions/manifest.json +10 -9
- predictions/players.parquet +2 -2
- style.css +7 -0
README.md
CHANGED
|
@@ -8,15 +8,17 @@ sdk_version: 6.28.0
|
|
| 8 |
python_version: "3.12"
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
| 11 |
-
short_description: Forecast football player market values
|
| 12 |
---
|
| 13 |
|
| 14 |
# Player Value Forecaster
|
| 15 |
|
| 16 |
-
CMU 24-679 Project 1 (Yunus Polatoglu & Jack Stevens). Search players by name (case and accents ignored) and filter by league, country, nationality, age and position, then select one to see their Transfermarkt value history and a
|
| 17 |
|
| 18 |
-
|
| 19 |
|
| 20 |
The page opens on the most valuable player, and four examples (Established star, Rising young player, Veteran in decline, Hardest to predict) are picked from the data by fixed rules each time the app starts, so they stay valid when the bundle changes.
|
| 21 |
|
| 22 |
-
|
|
|
|
|
|
|
|
|
| 8 |
python_version: "3.12"
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
| 11 |
+
short_description: Forecast football player market values one season ahead
|
| 12 |
---
|
| 13 |
|
| 14 |
# Player Value Forecaster
|
| 15 |
|
| 16 |
+
CMU 24-679 Project 1 (Yunus Polatoglu & Jack Stevens). Search players by name (case and accents ignored) and filter by league, country, nationality, age and position, then select one to see their Transfermarkt value history and a one-season forecast with a 10 to 90% range.
|
| 17 |
|
| 18 |
+
Sort by current value, biggest predicted rise or fall, or most uncertain forecast. The app reads the horizons from the bundle it is given: the current model forecasts one season, so the Look ahead control is hidden until a bundle carries more.
|
| 19 |
|
| 20 |
The page opens on the most valuable player, and four examples (Established star, Rising young player, Veteran in decline, Hardest to predict) are picked from the data by fixed rules each time the app starts, so they stay valid when the bundle changes.
|
| 21 |
|
| 22 |
+
Forecasts come from a four-feature LightGBM (age, position, current value and its change over the past year) trained on 500 hand-collected contracts. Those players were collected because they became valuable, so the forecasts lean upward; the app says so on the page.
|
| 23 |
+
|
| 24 |
+
Data: contract dates for 500 players, collected by hand by the team, and Transfermarkt values via the Kaggle dataset [player-scores](https://www.kaggle.com/datasets/davidcariboo/player-scores) by davidcariboo. Coursework only.
|
app.py
CHANGED
|
@@ -5,6 +5,7 @@ so the Space stays fast and the pipeline can change independently.
|
|
| 5 |
"""
|
| 6 |
import json
|
| 7 |
import math
|
|
|
|
| 8 |
import unicodedata
|
| 9 |
from datetime import datetime
|
| 10 |
from pathlib import Path
|
|
@@ -13,7 +14,8 @@ import gradio as gr
|
|
| 13 |
import pandas as pd
|
| 14 |
import plotly.graph_objects as go
|
| 15 |
|
| 16 |
-
|
|
|
|
| 17 |
MAX_ROWS = 200
|
| 18 |
AGE_FLOOR, AGE_CEILING = 15, 45
|
| 19 |
|
|
@@ -21,16 +23,29 @@ AGE_FLOOR, AGE_CEILING = 15, 45
|
|
| 21 |
COLUMNS = ["Player", "Age", "Position", "Club", "League", "Nationality", "Value",
|
| 22 |
"Change", "Likely range"]
|
| 23 |
|
| 24 |
-
#
|
| 25 |
-
|
|
|
|
|
|
|
| 26 |
DEFAULT_HORIZON = "1 season"
|
| 27 |
# Sort label to (column prefix, ascending); prefixes gain the horizon suffix
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
DEFAULT_SORT = "Current value"
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
CARD_PROMPT = "Select a player in the table."
|
| 35 |
CARD_GONE = "That player isn't in the current results. Select another player in the table."
|
| 36 |
CARD_MISSING = "That player could not be found in this bundle. Select another player in the table."
|
|
@@ -86,6 +101,40 @@ def normalise_name(text) -> str:
|
|
| 86 |
return " ".join(bare.translate(EXTRA_FOLDS).split())
|
| 87 |
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
def add_derived_columns(players, forecasts):
|
| 90 |
"""Precompute search keys and per horizon forecast numbers once at startup."""
|
| 91 |
players = players.copy()
|
|
@@ -115,7 +164,14 @@ def width_cutoffs(players) -> dict[int, float]:
|
|
| 115 |
|
| 116 |
|
| 117 |
PLAYERS, HISTORY, FORECASTS, MANIFEST = load_bundle()
|
| 118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
HISTORY_BY_ID, FORECASTS_BY_ID, PLAYER_BY_ID = build_lookups(PLAYERS, HISTORY, FORECASTS)
|
| 120 |
# Fixed at startup so a filter never moves what counts as wide
|
| 121 |
WIDTH_CUTOFF = width_cutoffs(PLAYERS)
|
|
@@ -316,13 +372,28 @@ def is_valued(p):
|
|
| 316 |
return p["current_value_eur"] >= MIN_EXAMPLE_VALUE
|
| 317 |
|
| 318 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 319 |
# (label, who qualifies, ranking column, take the largest); star goes first
|
| 320 |
-
# so it matches the featured player and no other rule can claim it
|
|
|
|
| 321 |
EXAMPLE_RULES = [
|
| 322 |
("Established star", lambda p: p["current_value_eur"].notna(), "current_value_eur", True),
|
| 323 |
-
("Rising young player",
|
| 324 |
-
|
| 325 |
-
("
|
|
|
|
|
|
|
| 326 |
]
|
| 327 |
|
| 328 |
|
|
@@ -335,7 +406,8 @@ def pick_examples(players) -> list[tuple[str, int, str]]:
|
|
| 335 |
if pool.empty:
|
| 336 |
continue
|
| 337 |
best = pool.sort_values([col, "player_id"], ascending=[not largest, True]).iloc[0]
|
| 338 |
-
|
|
|
|
| 339 |
taken.add(int(best["player_id"]))
|
| 340 |
return picks
|
| 341 |
|
|
@@ -383,7 +455,7 @@ def money_ticks(top: float, target: int = 5) -> tuple[list[float], list[str]]:
|
|
| 383 |
|
| 384 |
|
| 385 |
def make_chart(pid: int):
|
| 386 |
-
"""Value history line plus
|
| 387 |
player = PLAYER_BY_ID.get(pid)
|
| 388 |
if player is None:
|
| 389 |
return None
|
|
@@ -507,7 +579,8 @@ def change_text(p50, current, value_date=None) -> str:
|
|
| 507 |
def spread_text(rows: dict) -> str:
|
| 508 |
"""How the range's width moves from the nearest to the furthest horizon."""
|
| 509 |
first, last = min(HORIZONS.values()), max(HORIZONS.values())
|
| 510 |
-
|
|
|
|
| 511 |
return ""
|
| 512 |
near = rows[first].p90_eur - rows[first].p10_eur
|
| 513 |
far = rows[last].p90_eur - rows[last].p10_eur
|
|
@@ -550,8 +623,9 @@ def make_explanation(pid, horizon: int = 1) -> str:
|
|
| 550 |
"real value to land inside this range 8 times out of 10.")
|
| 551 |
# The forecast's anchor is when its knowledge stops, not the last valuation
|
| 552 |
anchor = fmt_day(getattr(r, "anchor_date", None)) or "the forecast was made"
|
| 553 |
-
limits = ("<small>Based
|
| 554 |
-
|
|
|
|
| 555 |
|
| 556 |
parts = [EXPLAIN_TITLE]
|
| 557 |
n_history = history_count(pid)
|
|
@@ -566,6 +640,22 @@ def make_explanation(pid, horizon: int = 1) -> str:
|
|
| 566 |
return "\n\n".join(parts)
|
| 567 |
|
| 568 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 569 |
def make_footer(manifest: dict) -> str:
|
| 570 |
"""Credits, coursework notice and bundle stamp shown under everything."""
|
| 571 |
version = manifest.get("model_version") or "unknown"
|
|
@@ -577,11 +667,10 @@ def make_footer(manifest: dict) -> str:
|
|
| 577 |
kaggle = "https://www.kaggle.com/datasets"
|
| 578 |
# Credits open in a new tab so filter state survives
|
| 579 |
return (
|
| 580 |
-
'<p>Data:
|
|
|
|
| 581 |
f'<a href="{kaggle}/davidcariboo/player-scores" target="_blank" rel="noopener">player-scores</a>'
|
| 582 |
-
' by davidcariboo
|
| 583 |
-
f'<a href="{kaggle}/xfkzujqjvx97n/football-datasets" target="_blank" rel="noopener">football-datasets</a>'
|
| 584 |
-
' by salimt.</p>'
|
| 585 |
'<p>Coursework for CMU 24-679 (Yunus Polatoglu & Jack Stevens). '
|
| 586 |
'Not for transfer or betting decisions.</p>'
|
| 587 |
f'<p>Model {version}, built {built}.</p>'
|
|
@@ -613,7 +702,29 @@ CSS = (Path(__file__).parent / "style.css").read_text(encoding="utf-8")
|
|
| 613 |
|
| 614 |
APP_TITLE = "Player Value Forecaster"
|
| 615 |
LOOK_AHEAD_INFO = "How many seasons ahead the forecast looks"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 616 |
SORT_INFO = "Order the table by value, predicted change or how uncertain the forecast is"
|
|
|
|
|
|
|
|
|
|
| 617 |
TABLE_NOTE = ("⚠ low-confidence forecast. Likely range: where the model aims for the real "
|
| 618 |
"value to land 8 times out of 10.")
|
| 619 |
|
|
@@ -621,19 +732,21 @@ with gr.Blocks(title=APP_TITLE) as demo:
|
|
| 621 |
ids_state = gr.State([])
|
| 622 |
selected_state = gr.State(None)
|
| 623 |
|
| 624 |
-
gr.HTML("""
|
| 625 |
<header class="pvf-head">
|
| 626 |
<h1>Player value forecaster</h1>
|
| 627 |
<p>Pick a football player to see where their Transfermarkt value is likely heading
|
| 628 |
-
over the next
|
| 629 |
</header>""")
|
| 630 |
if MANIFEST.get("is_mock"):
|
| 631 |
gr.HTML('<div class="pvf-mock">Demo data: these players and forecasts are invented '
|
| 632 |
'while the models are being trained.</div>')
|
|
|
|
|
|
|
| 633 |
|
| 634 |
# Results are built first so the examples can target them, placed below
|
| 635 |
horizon = gr.Radio(list(HORIZONS), value=DEFAULT_HORIZON, label="Look ahead",
|
| 636 |
-
info=LOOK_AHEAD_INFO, render=False)
|
| 637 |
sort_by = gr.Dropdown(list(SORTS), value=DEFAULT_SORT, label="Sort by", info=SORT_INFO,
|
| 638 |
render=False)
|
| 639 |
count = gr.Markdown(render=False)
|
|
@@ -692,11 +805,7 @@ with gr.Blocks(title=APP_TITLE) as demo:
|
|
| 692 |
card.render()
|
| 693 |
|
| 694 |
with gr.Accordion("How the forecast works", open=False, elem_classes="pvf-how"):
|
| 695 |
-
gr.Markdown(
|
| 696 |
-
"Each forecast predicts the change in value 1, 2 and 3 seasons after the "
|
| 697 |
-
"1 July snapshot. The shaded band is the range the model expects the value to land "
|
| 698 |
-
"in 8 times out of 10. The model will be tested on past seasons it never saw. "
|
| 699 |
-
"Results will appear here once the real model is in.")
|
| 700 |
|
| 701 |
# Footer sits outside every container so it stays visible at all times
|
| 702 |
gr.HTML(make_footer(MANIFEST), elem_classes="pvf-foot")
|
|
|
|
| 5 |
"""
|
| 6 |
import json
|
| 7 |
import math
|
| 8 |
+
import os
|
| 9 |
import unicodedata
|
| 10 |
from datetime import datetime
|
| 11 |
from pathlib import Path
|
|
|
|
| 14 |
import pandas as pd
|
| 15 |
import plotly.graph_objects as go
|
| 16 |
|
| 17 |
+
# Tests point this at a fixed mock bundle; the Space always uses ./predictions
|
| 18 |
+
BUNDLE_DIR = Path(os.environ.get("PVF_BUNDLE_DIR", Path(__file__).parent / "predictions"))
|
| 19 |
MAX_ROWS = 200
|
| 20 |
AGE_FLOOR, AGE_CEILING = 15, 45
|
| 21 |
|
|
|
|
| 23 |
COLUMNS = ["Player", "Age", "Position", "Club", "League", "Nationality", "Value",
|
| 24 |
"Change", "Likely range"]
|
| 25 |
|
| 26 |
+
# Every horizon this app can label; the bundle decides which are offered
|
| 27 |
+
HORIZON_LABELS = {1: "1 season", 2: "2 seasons", 3: "3 seasons"}
|
| 28 |
+
# Replaced at startup by the horizons the loaded bundle actually forecasts
|
| 29 |
+
HORIZONS = {label: h for h, label in HORIZON_LABELS.items()}
|
| 30 |
DEFAULT_HORIZON = "1 season"
|
| 31 |
# Sort label to (column prefix, ascending); prefixes gain the horizon suffix
|
| 32 |
+
SORT_RULES = {"Current value": ("current_value_eur", False),
|
| 33 |
+
"Biggest predicted rise": ("change", False),
|
| 34 |
+
"Biggest predicted fall": ("change", True),
|
| 35 |
+
"Most uncertain": ("width", False)}
|
| 36 |
+
# Renamed at startup when the bundle predicts no falls for this label to find
|
| 37 |
+
FALL_LABEL = "Biggest predicted fall"
|
| 38 |
+
NO_FALL_LABEL = "Smallest predicted rise"
|
| 39 |
+
SORTS = dict(SORT_RULES)
|
| 40 |
DEFAULT_SORT = "Current value"
|
| 41 |
|
| 42 |
+
# Text columns shown to the user, where a gap must not read as nan
|
| 43 |
+
LABEL_COLUMNS = ["position", "sub_position", "club_name", "league_name",
|
| 44 |
+
"league_country", "nationality"]
|
| 45 |
+
UNKNOWN_LABEL = "Unknown"
|
| 46 |
+
# Placeholders the pipeline writes for a field it could not fill
|
| 47 |
+
MISSING_TOKENS = {"", "missing", "unknown", "none", "na", "n/a", "nan"}
|
| 48 |
+
|
| 49 |
CARD_PROMPT = "Select a player in the table."
|
| 50 |
CARD_GONE = "That player isn't in the current results. Select another player in the table."
|
| 51 |
CARD_MISSING = "That player could not be found in this bundle. Select another player in the table."
|
|
|
|
| 101 |
return " ".join(bare.translate(EXTRA_FOLDS).split())
|
| 102 |
|
| 103 |
|
| 104 |
+
def offered_horizons(forecasts) -> dict[str, int]:
|
| 105 |
+
"""Label to seasons for the horizons this bundle really forecasts."""
|
| 106 |
+
present = sorted({int(h) for h in forecasts["horizon"].dropna().unique()
|
| 107 |
+
if int(h) in HORIZON_LABELS})
|
| 108 |
+
# A bundle with no usable horizon still leaves the control working
|
| 109 |
+
return {HORIZON_LABELS[h]: h for h in present or [1]}
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
def sort_labels(players, horizon: int) -> dict[str, tuple[str, bool]]:
|
| 113 |
+
"""Rename the fall sort when nothing in this bundle is predicted to fall."""
|
| 114 |
+
change = players.get(f"change_{horizon}")
|
| 115 |
+
if change is not None and (change < 0).any():
|
| 116 |
+
return dict(SORT_RULES)
|
| 117 |
+
# Sorting ascending would surface the smallest rises, not any fall
|
| 118 |
+
return {NO_FALL_LABEL if k == FALL_LABEL else k: v for k, v in SORT_RULES.items()}
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
def falling_share(players, horizon: int) -> float:
|
| 122 |
+
"""Share of players the bundle predicts will lose value."""
|
| 123 |
+
change = players[f"change_{horizon}"].dropna()
|
| 124 |
+
return 0.0 if change.empty else float((change < 0).mean())
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def clean_labels(players):
|
| 128 |
+
"""Nulls and pipeline placeholders become one Unknown, never a shown nan."""
|
| 129 |
+
players = players.copy()
|
| 130 |
+
for col in LABEL_COLUMNS:
|
| 131 |
+
# Strip first, so " " and "Missing " are caught alongside a true null
|
| 132 |
+
text = players[col].astype("string").str.strip()
|
| 133 |
+
unknown = text.isna() | text.str.lower().isin(MISSING_TOKENS)
|
| 134 |
+
players[col] = text.mask(unknown, UNKNOWN_LABEL)
|
| 135 |
+
return players
|
| 136 |
+
|
| 137 |
+
|
| 138 |
def add_derived_columns(players, forecasts):
|
| 139 |
"""Precompute search keys and per horizon forecast numbers once at startup."""
|
| 140 |
players = players.copy()
|
|
|
|
| 164 |
|
| 165 |
|
| 166 |
PLAYERS, HISTORY, FORECASTS, MANIFEST = load_bundle()
|
| 167 |
+
# The model dropped to one horizon, so the control follows the bundle
|
| 168 |
+
HORIZONS = offered_horizons(FORECASTS)
|
| 169 |
+
DEFAULT_HORIZON = next(iter(HORIZONS))
|
| 170 |
+
DEFAULT_H = HORIZONS[DEFAULT_HORIZON]
|
| 171 |
+
PLAYERS = add_derived_columns(clean_labels(PLAYERS), FORECASTS)
|
| 172 |
+
# Labels are settled here, once the forecasts are known
|
| 173 |
+
SORTS = sort_labels(PLAYERS, DEFAULT_H)
|
| 174 |
+
FALLING_SHARE = falling_share(PLAYERS, DEFAULT_H)
|
| 175 |
HISTORY_BY_ID, FORECASTS_BY_ID, PLAYER_BY_ID = build_lookups(PLAYERS, HISTORY, FORECASTS)
|
| 176 |
# Fixed at startup so a filter never moves what counts as wide
|
| 177 |
WIDTH_CUTOFF = width_cutoffs(PLAYERS)
|
|
|
|
| 372 |
return p["current_value_eur"] >= MIN_EXAMPLE_VALUE
|
| 373 |
|
| 374 |
|
| 375 |
+
def directional_label(rising: str, falling: str):
|
| 376 |
+
"""Label chosen from the sign of the picked player's own forecast."""
|
| 377 |
+
def choose(row) -> str:
|
| 378 |
+
change = row.get(CHANGE_COL)
|
| 379 |
+
# Only claim a decline when this player really is forecast to fall
|
| 380 |
+
return falling if pd.notna(change) and change < 0 else rising
|
| 381 |
+
return choose
|
| 382 |
+
|
| 383 |
+
|
| 384 |
+
# Ranking columns follow the bundle, since a horizon other than 1 may be all it has
|
| 385 |
+
CHANGE_COL, WIDTH_COL = f"change_{DEFAULT_H}", f"width_{DEFAULT_H}"
|
| 386 |
+
|
| 387 |
# (label, who qualifies, ranking column, take the largest); star goes first
|
| 388 |
+
# so it matches the featured player and no other rule can claim it. A label
|
| 389 |
+
# may be a function of the picked row, for the two that assert a direction.
|
| 390 |
EXAMPLE_RULES = [
|
| 391 |
("Established star", lambda p: p["current_value_eur"].notna(), "current_value_eur", True),
|
| 392 |
+
(directional_label("Rising young player", "Young player in decline"),
|
| 393 |
+
lambda p: (p["age"] <= 23) & is_valued(p), CHANGE_COL, True),
|
| 394 |
+
(directional_label("Veteran: smallest predicted rise", "Veteran in decline"),
|
| 395 |
+
lambda p: (p["age"] >= 31) & is_valued(p), CHANGE_COL, False),
|
| 396 |
+
("Hardest to predict", is_valued, WIDTH_COL, True),
|
| 397 |
]
|
| 398 |
|
| 399 |
|
|
|
|
| 406 |
if pool.empty:
|
| 407 |
continue
|
| 408 |
best = pool.sort_values([col, "player_id"], ascending=[not largest, True]).iloc[0]
|
| 409 |
+
text = label(best) if callable(label) else label
|
| 410 |
+
picks.append((text, int(best["player_id"]), best["name"]))
|
| 411 |
taken.add(int(best["player_id"]))
|
| 412 |
return picks
|
| 413 |
|
|
|
|
| 455 |
|
| 456 |
|
| 457 |
def make_chart(pid: int):
|
| 458 |
+
"""Value history line plus every bundled horizon with a 10 to 90% band."""
|
| 459 |
player = PLAYER_BY_ID.get(pid)
|
| 460 |
if player is None:
|
| 461 |
return None
|
|
|
|
| 579 |
def spread_text(rows: dict) -> str:
|
| 580 |
"""How the range's width moves from the nearest to the furthest horizon."""
|
| 581 |
first, last = min(HORIZONS.values()), max(HORIZONS.values())
|
| 582 |
+
# One horizon leaves nothing to compare, so the sentence is dropped
|
| 583 |
+
if first == last or first not in rows or last not in rows:
|
| 584 |
return ""
|
| 585 |
near = rows[first].p90_eur - rows[first].p10_eur
|
| 586 |
far = rows[last].p90_eur - rows[last].p10_eur
|
|
|
|
| 623 |
"real value to land inside this range 8 times out of 10.")
|
| 624 |
# The forecast's anchor is when its knowledge stops, not the last valuation
|
| 625 |
anchor = fmt_day(getattr(r, "anchor_date", None)) or "the forecast was made"
|
| 626 |
+
limits = ("<small>Based on past Transfermarkt valuations, age, position and the contract "
|
| 627 |
+
"we looked up by hand. It does not know about injuries, new contracts or "
|
| 628 |
+
f"transfers after {anchor}.</small>")
|
| 629 |
|
| 630 |
parts = [EXPLAIN_TITLE]
|
| 631 |
n_history = history_count(pid)
|
|
|
|
| 640 |
return "\n\n".join(parts)
|
| 641 |
|
| 642 |
|
| 643 |
+
def optimism_note(players, horizon: int) -> str:
|
| 644 |
+
"""Warn when forecasts lean one way, so the training bias is visible."""
|
| 645 |
+
change = players[f"change_{horizon}"].dropna()
|
| 646 |
+
if change.empty:
|
| 647 |
+
return ""
|
| 648 |
+
rising = float((change > 0).mean())
|
| 649 |
+
# Only worth saying when the lean is strong enough to mislead
|
| 650 |
+
if rising < 0.6:
|
| 651 |
+
return ""
|
| 652 |
+
typical = float(change.median()) + 1
|
| 653 |
+
return (f"These forecasts lean optimistic: {rising:.0%} of players are predicted to rise, "
|
| 654 |
+
f"typically to {typical:.1f} times their current value. The model learned from "
|
| 655 |
+
"500 players collected because they became valuable, so it has seen few careers "
|
| 656 |
+
"that stall or fade. Read the direction with that in mind.")
|
| 657 |
+
|
| 658 |
+
|
| 659 |
def make_footer(manifest: dict) -> str:
|
| 660 |
"""Credits, coursework notice and bundle stamp shown under everything."""
|
| 661 |
version = manifest.get("model_version") or "unknown"
|
|
|
|
| 667 |
kaggle = "https://www.kaggle.com/datasets"
|
| 668 |
# Credits open in a new tab so filter state survives
|
| 669 |
return (
|
| 670 |
+
'<p>Data: contract dates for 500 players collected by hand by the team; '
|
| 671 |
+
'Transfermarkt values, via the Kaggle dataset '
|
| 672 |
f'<a href="{kaggle}/davidcariboo/player-scores" target="_blank" rel="noopener">player-scores</a>'
|
| 673 |
+
' by davidcariboo.</p>'
|
|
|
|
|
|
|
| 674 |
'<p>Coursework for CMU 24-679 (Yunus Polatoglu & Jack Stevens). '
|
| 675 |
'Not for transfer or betting decisions.</p>'
|
| 676 |
f'<p>Model {version}, built {built}.</p>'
|
|
|
|
| 702 |
|
| 703 |
APP_TITLE = "Player Value Forecaster"
|
| 704 |
LOOK_AHEAD_INFO = "How many seasons ahead the forecast looks"
|
| 705 |
+
# Horizon wording is written once here, since three places repeat it
|
| 706 |
+
HORIZON_SPAN = (seasons_text(max(HORIZONS.values())) if len(HORIZONS) == 1 else
|
| 707 |
+
f"one to {max(HORIZONS.values())} seasons")
|
| 708 |
+
# "over the next ..." reads better with a bare noun than with "1 season"
|
| 709 |
+
HEAD_SPAN = "season" if list(HORIZONS.values()) == [1] else HORIZON_SPAN
|
| 710 |
+
OPTIMISM_NOTE = optimism_note(PLAYERS, horizon_of(DEFAULT_HORIZON))
|
| 711 |
+
HOW_IT_WORKS = (
|
| 712 |
+
f"Each forecast predicts the change in value {HORIZON_SPAN} after the "
|
| 713 |
+
"1 July snapshot, from the player's age, position, current value and how that value "
|
| 714 |
+
"moved over the past year. The shaded band is where the model expects the real value "
|
| 715 |
+
"to land 8 times out of 10.\n\n"
|
| 716 |
+
"It was trained on 500 contracts we collected by hand, each reused for its other "
|
| 717 |
+
"seasons to reach 1,000 samples, and tested by five-fold cross-validation grouped by "
|
| 718 |
+
"player, so no player appears in both training and test data. A walk-forward check on "
|
| 719 |
+
"five named players put 6 of 10 forecasts inside the band.\n\n"
|
| 720 |
+
"Known limits: those 500 players were chosen because they became valuable, which is "
|
| 721 |
+
"why the forecasts lean upward; the model cannot see injuries, transfers or contract "
|
| 722 |
+
"news after the snapshot; and players much older or cheaper than the training set are "
|
| 723 |
+
"extrapolations.")
|
| 724 |
SORT_INFO = "Order the table by value, predicted change or how uncertain the forecast is"
|
| 725 |
+
# Naming the share stops the fall sort implying falls are common here
|
| 726 |
+
if 0 < FALLING_SHARE < 0.1:
|
| 727 |
+
SORT_INFO += f". Only {FALLING_SHARE:.0%} of players are predicted to fall"
|
| 728 |
TABLE_NOTE = ("⚠ low-confidence forecast. Likely range: where the model aims for the real "
|
| 729 |
"value to land 8 times out of 10.")
|
| 730 |
|
|
|
|
| 732 |
ids_state = gr.State([])
|
| 733 |
selected_state = gr.State(None)
|
| 734 |
|
| 735 |
+
gr.HTML(f"""
|
| 736 |
<header class="pvf-head">
|
| 737 |
<h1>Player value forecaster</h1>
|
| 738 |
<p>Pick a football player to see where their Transfermarkt value is likely heading
|
| 739 |
+
over the next {HEAD_SPAN}.</p>
|
| 740 |
</header>""")
|
| 741 |
if MANIFEST.get("is_mock"):
|
| 742 |
gr.HTML('<div class="pvf-mock">Demo data: these players and forecasts are invented '
|
| 743 |
'while the models are being trained.</div>')
|
| 744 |
+
elif OPTIMISM_NOTE:
|
| 745 |
+
gr.HTML(f'<div class="pvf-mock">{OPTIMISM_NOTE}</div>')
|
| 746 |
|
| 747 |
# Results are built first so the examples can target them, placed below
|
| 748 |
horizon = gr.Radio(list(HORIZONS), value=DEFAULT_HORIZON, label="Look ahead",
|
| 749 |
+
info=LOOK_AHEAD_INFO, render=False, visible=len(HORIZONS) > 1)
|
| 750 |
sort_by = gr.Dropdown(list(SORTS), value=DEFAULT_SORT, label="Sort by", info=SORT_INFO,
|
| 751 |
render=False)
|
| 752 |
count = gr.Markdown(render=False)
|
|
|
|
| 805 |
card.render()
|
| 806 |
|
| 807 |
with gr.Accordion("How the forecast works", open=False, elem_classes="pvf-how"):
|
| 808 |
+
gr.Markdown(HOW_IT_WORKS)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 809 |
|
| 810 |
# Footer sits outside every container so it stays visible at all times
|
| 811 |
gr.HTML(make_footer(MANIFEST), elem_classes="pvf-foot")
|
predictions/forecasts.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b3481ff975d128663c9b87a496673e57b8dea89a97105ead0d5d086539afc851
|
| 3 |
+
size 142572
|
predictions/history.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1cf321f316ed85b753e7acc111fc618c81c0770a188913ea7c87eff6c3ea2428
|
| 3 |
+
size 262835
|
predictions/manifest.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
| 1 |
-
{
|
| 2 |
-
"created_at": "2026-09-
|
| 3 |
-
"is_mock":
|
| 4 |
-
"model_version": "
|
| 5 |
-
"data_versions": {
|
| 6 |
-
"player-scores": "
|
| 7 |
-
"
|
| 8 |
-
|
| 9 |
-
|
|
|
|
| 10 |
}
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"created_at": "2026-09-29T17:42:25+00:00",
|
| 3 |
+
"is_mock": false,
|
| 4 |
+
"model_version": "lgbm-core-v1",
|
| 5 |
+
"data_versions": {
|
| 6 |
+
"player-scores": "valuations through 2026-06-12",
|
| 7 |
+
"samples": "1000 rows",
|
| 8 |
+
"panel_anchor": "2026-07-01"
|
| 9 |
+
},
|
| 10 |
+
"notes": "One-season forecasts from 2026-07-01 by the 4-feature core LightGBM, trained on the 1000 contract samples. Caveat: those samples are survivor-biased (median training change +0.34 log, 71% rose; all panel players 2013-2025: -0.10, 32% rose), so medians lean upward. 96% of these forecasts predict a rise, median +0.94 log. Training covered ages 16-31 and values from EUR 0.75M (10th percentile); forecasts outside that range, mostly older and cheaper players, are extrapolations."
|
| 11 |
}
|
predictions/players.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:32dff53a07d0fdac233944c1763007ece7772f7358547b63f357c9445c3bffd6
|
| 3 |
+
size 142643
|
style.css
CHANGED
|
@@ -138,6 +138,13 @@ div.pvf-chart .main-svg .gridlayer path { stroke: var(--border-color-primary) !i
|
|
| 138 |
div.pvf-main input[type=range] {
|
| 139 |
box-sizing: content-box; padding: 18px 0; background-clip: content-box;
|
| 140 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
/* Plotly's 22px toolbar icons are too small to tap, so hide them */
|
| 142 |
div.pvf-chart .modebar-container { display: none; }
|
| 143 |
}
|
|
|
|
| 138 |
div.pvf-main input[type=range] {
|
| 139 |
box-sizing: content-box; padding: 18px 0; background-clip: content-box;
|
| 140 |
}
|
| 141 |
+
/* The card's forecast table has three columns in 390px, so Median broke
|
| 142 |
+
as "Media n" and a value as "EUR 70.4 m". Keep each cell on one line
|
| 143 |
+
and let the table scroll sideways inside the card if it still overflows. */
|
| 144 |
+
div.prose.pvf-card div:has(> table) { overflow-x: auto; }
|
| 145 |
+
div.prose.pvf-card th, div.prose.pvf-card td { white-space: nowrap; }
|
| 146 |
+
/* Padding is the first thing to give back when the columns are tight */
|
| 147 |
+
div.prose.pvf-card th, div.prose.pvf-card td { padding-left: 6px; padding-right: 6px; }
|
| 148 |
/* Plotly's 22px toolbar icons are too small to tap, so hide them */
|
| 149 |
div.pvf-chart .modebar-container { display: none; }
|
| 150 |
}
|