Skip to content
mkearneyPublic

About

Source for hoop2vec.net, a basketball advanced analytics website for the NCAA, NBA, and WNBA. Teams and players. No ads, no account.

Topics

Resources

Stars

5 stars

Watchers

0 watching

Forks

Repository files navigation

hoop2vec

Power ratings, game forecasts, player values, and team styles for men's and women's college basketball, the NBA, and the WNBA. The college sites add draft prospects and NCAA bracket odds. The pro sites add playoff odds. NBA games and the biggest college games get live pages with win probability after every play. The site is hoop2vec.net. It's free, has no ads, and everything that runs it is in this repository.

Ratings update a few minutes after each game ends and are rebuilt from scratch every morning. Every forecast uses only what was known before tip-off, and the models are graded on seasons they never saw.

How it works

Each team gets an adjusted efficiency rating, an Elo rating, and a dynamic (Kalman) rating that starts each season from its roster. Each player gets a point-in-time value: box plus/minus in college, and a box model fitted to lineup RAPM in the pros. Roster strength is the minute-weighted sum, minus whoever is likely to sit.

A linear model and a matchup neural network turn all of that into a predicted margin and a win probability. Power is a team's average predicted margin against strong opposition on a neutral floor. Bracket odds are exact, round by round. Pro playoff odds come from playing out the season 10,000 times.

The site's Method page has a card for every model, with its version, how it was tested, and how it did. The text and change logs live in hoop2vec/model_cards.py, and the numbers come from the stored backtests. To change a model, add a line to its change log. tests/test_model_cards.py checks the cards against the backtests. research/ has the experiments.

Live games

Every NBA game has its own page with the score, win probability through the game, the biggest swings, team and player numbers, and every play. Men's and women's college games get the same page when either team is in the top 25 by Power going into the game, and so does every conference tournament and NCAA tournament game. The pipeline decides which games qualify (live_events in hoop2vec/pipeline.py) and gives only those an ESPN id in the site data. The reader's browser polls ESPN's live game feed every 20 seconds while the game is on. No server is involved, so there's nothing to scale on a busy night. The Games page cards update the same way, from the scoreboard feed. The WNBA doesn't have game pages yet.

Win probability comes from the site's own model. It's a gradient-boosted classifier (scikit-learn's HistGradientBoosting) on the score, the time left, who has the ball, home court, and the pregame forecast. Two inputs combine these the way a simple model of a basketball game would: the margin the home team can expect at the end, divided by the square root of the time left, and the ball's worth on the same scale. Monotonic constraints keep it sensible: a bigger lead, a better forecast, or the ball can only help.

Each league has its own model, since the clock and the rules differ. The men's college game has two 20-minute halves, the women's has four 10-minute quarters, and the NBA has four 12-minute quarters. In the NBA the rules say who gets the ball at the start of each quarter. College uses a possession arrow that held balls also turn, so a college period starts with nobody's ball until its first play.

It learns from game states. The play-by-play ingest keeps the score, the clock, and who has the ball after every moment of every game (game_states in hoop2vec/sources/pbp.py). hoop2vec/winprob.py trains on every game with play-by-play and a season-ahead pregame forecast: NBA seasons since 2012, men's since 2015, and women's since 2022. Each game is paired with its forecast from the season-ahead backtest. The model is exported as plain decision trees in artifacts/<league>/live_model.json. app.js builds the same states from the live feed and walks the trees. tests/test_winprob.py checks the state rules and that the exported trees match the fitted model.

In a season-ahead backtest from 2016 to 2026 (4,474,612 moments in 14,041 games), the NBA model's log loss is 0.462 per moment. A coin flip scores 0.693. Holding the pregame forecast all game scores 0.614, and the same model without the forecast scores 0.493. The forecast matters most early: in the first quarter the model scores 0.594, against 0.614 for the forecast alone and 0.653 without it. Its stated chances are off by 1.1 percentage points on average.

The men's model, graded from 2019 to 2026 (8,657,573 moments in 39,207 games), scores 0.383. The pregame forecast alone scores 0.521, and the model without it scores 0.438. In the first half it scores 0.469, against 0.519 for the forecast alone and 0.557 without it. Its stated chances are off by 0.2 percentage points on average.

The women's model, graded from 2024 to 2026 (3,896,386 moments in 16,222 games), scores 0.323. The pregame forecast alone scores 0.451, and the model without it scores 0.396. In the first quarter it scores 0.428, against 0.448 for the forecast alone. Its stated chances are off by 0.3 percentage points on average. College games are more lopsided than NBA games, so every score is lower.

How it does

Season-ahead backtests: each season is predicted by models trained only on earlier seasons. Log loss scores each win probability, and confident misses cost the most. Lower is better:

All games hoop2vec, games with a line Sportsbook line, same games
Men's, 2012 to 2026 0.5160 0.5446 0.5422
Women's, 2022 to 2026 0.4592 0.3890 0.3956
NBA, 2012 to 2026 0.6092 0.5965 0.5812
WNBA 0.6141

A sharp sportsbook still beats it in the men's game and the NBA. On 65,392 men's games since 2015, it beats T-Rank's stored pre-game odds in all 12 seasons (0.5203 against 0.5275).

Data

Men's college games, box scores, player stats, and draft picks come from barttorvik.com. Its T-Rank pre-game odds are a benchmark, never an input. ESPN's public API covers the women's game and the pros. It also supplies play-by-play, lineups, shot locations, standings, closing lines, the bracket, and the newest men's games. Basketball-Reference has NBA and WNBA careers and WNBA drafts. Men's college injury reports come from Covers.com and Rotowire. The US Cities Database gives coordinates for travel distance.

Requests identify themselves as hoop2vec-research/1.0. Calls to barttorvik.com are at least 10 seconds apart, as its robots.txt asks.

Running it

pip install torch --index-url https://download.pytorch.org/whl/cpu
pip install -r requirements.txt
python -m hoop2vec daily       # refresh the season and rebuild the site data
python -m hoop2vec live        # the same, as games finish
python -m hoop2vec train       # retrain the game models (and, NBA, in-game win probability)
python -m hoop2vec backtest    # season-ahead backtest of every model
python -m hoop2vec site        # page shells, team pages, and crawl files
python -m hoop2vec states 2012-2026 --nba   # game states for in-game win probability (once; train fetches any missing)

Add --womens, --nba, or --wnba for the other leagues (men's is the default). Hand edits for injuries and the bracket go in overrides/<league>/.

Big downloads get a copy in our own S3 bucket, so a backfill reads from there before asking the source again. scripts/s3_data.sh pull and push do the copying, and design/s3_data.md has the details.

Every live check also saves the betting lines and our published forecasts for all five leagues (basketball here, football from hike2vec) to the same bucket. design/market.md explains what's in each snapshot and how to use it.

Site data changes several times a day, so it lives on the site-data branch instead of main. To preview locally, run scripts/site_data.sh pull, then python -m hoop2vec site, then cd docs && python -m http.server.

GitHub Actions handles the rest (.github/workflows/): the morning refresh, live updates every 10 minutes, a monthly retrain, tests, a browser smoke test, and the Pages deploy.

Origin

I've built college basketball models for more than a decade. hoop2vec is where that work landed: a final push with Claude Code scaled the ideas to four leagues and put a real front end on them.

About

Source for hoop2vec.net, a basketball advanced analytics website for the NCAA, NBA, and WNBA. Teams and players. No ads, no account.

Topics

Resources

Stars

5 stars

Watchers

0 watching

Forks

Contributors

Languages