This project predicts professional Counter-Strike 2 matches: which maps are likely to be played, which team wins each map, and who takes the series. It started as an attempt to go beyond a single Jupyter notebook and actually build the thing the way a real ML system would be put together — separate stages for cleaning the data, engineering features, training a model, and serving predictions through an API, instead of one long script.
Live demo: fragpredict.org: pick two teams and a format (Bo1/Bo3/Bo5) to see the likely maps, each map's win probability and the series odds. You can also swap in maps of your own choice.
🇹🇷 Türkçe README için README.tr.md dosyasına bakın.
Give it two teams and a map — say, Team Vitality vs Natus Vincere on Mirage — and it returns a calibrated win probability for each side. If the maps aren't known yet, a second model predicts the map veto: which maps are likely to come up, and with them the series probability and score distribution. The map model is a logistic regression (it matched or beat XGBoost, LightGBM and CatBoost on a held-out validation period) trained on about three years of professional match history, served through a FastAPI endpoint, with predictions logged to a Postgres database (Supabase) so they can be reviewed later.
raw CSVs (pro match history)
│
▼
src/eda_cleaning.py → cleaning, schema validation, leakage-aware target derivation
│
▼
src/pipeline.py → leakage-free feature engineering (player ratings, form, H2H,
│ roster stability, player firepower, map-specific Elo...)
▼
src/train.py → chronological train/val/test split, logistic regression /
│ XGBoost / LightGBM / CatBoost comparison (champion picked on
│ validation), Optuna tuning, probability calibration
▼
src/predict.py → inference layer (reuses pipeline.py's feature functions to
│ avoid train/serve skew)
▼
api/main.py → FastAPI service, /api/v1/predict, Supabase logging
The map veto model sits next to it: src/eda_cleaning.py also writes each match's map
order and the map pool on that date (match_veto.parquet), src/veto.py learns the veto
from it and src/series.py combines it with the map model into series probabilities.
The current champion model (logistic regression, sigmoid-calibrated) evaluated on a strictly chronological, held-out test period (May 28 – Nov 7, 2026: 2,080 maps from 1,027 matches, unseen during training). The champion is picked on the validation period, so the test period played no part in choosing it:
| Metric | Value | 95% CI |
|---|---|---|
| ROC-AUC | 0.651 | 0.626 – 0.674 |
| Log Loss | 0.654 | 0.641 – 0.666 |
| Brier Score | 0.231 | 0.225 – 0.237 |
| Accuracy @ 0.5 | 60.6% | 58.4% – 62.8% |
Confidence intervals come from a bootstrap over the 1,027 test matches (maps of the same match are resampled together).
On the same test period, the previous version of the model (43 features built around a team-name Elo) had a log loss of 0.6588; the new one is lower by 0.0053 (paired bootstrap 95% CI 0.0007 – 0.0098). The live site doesn't know the lineups in advance, which roughly halves that gain; see Limitations.
Predictions are order-invariant: "A vs B" and "B vs A" always get exactly complementary probabilities (see team order bias).
The veto model treats a Bo3 veto as an ordering of the 7 pool maps (ban, ban, pick, pick, ban, ban, decider). Each step is a choice among the remaining maps, driven by both teams' recent play share, map Elo, win rate and experience on each map. The data shows which maps were played, but not the bans or which team started the veto, so the model sums over every veto that matches what was played. Same chronological periods as the map model (validation Nov 2025 – May 2026, test May – Nov 2026), Bo3 matches:
| Validation / test | Model | Random |
|---|---|---|
| Probability the model gives its most likely 3 maps | 14.4% / 15.0% | – |
| How often those 3 maps were exactly the ones that came up (any order) | 17.5% / 14.0% | 2.9% |
| Played maps that were in the model's top 3 | 64.5% / 60.5% | 42.9% |
| Decider correct (where known) | 26.5% / 24.9% | 14.3% |
Series winner (Bo3, 630 / 851 matches):
| Validation / test | Log loss | Accuracy |
|---|---|---|
| Veto model × map model | 0.605 / 0.622 | 67.0% / 63.3% |
| All 7 maps weighted equally × map model | 0.605 / 0.620 | 66.5% / 63.8% |
| Elo only | 0.623 / 0.657 | 64.0% / 61.2% |
The series probability beats Elo alone (test log loss −0.035, 95% CI −0.050 to −0.021), but the veto model's map weights don't improve it; see Limitations. The veto model is there for the product: it says which maps are likely to come up, with probabilities that held up on unseen data.
Maps within a series aren't independent. How both teams play on the day carries over to every map, so 2-0 sweeps are more common than independent maps would imply. The table above treats maps as independent; the series probability on the site adds a shared per-series effect (σ = 0.657 on the logit scale, fit on data from before the test period). Each map keeps its own probability and the series winner is practically unchanged (test log loss 0.622 → 0.621, same accuracy), but the score distribution is better: the predicted share of Bo3 series that go to a third map drops from 46.3% to 42.4% on test, where 42.4% actually did.
For context: CS2 is a high-variance game and near-perfect prediction is not a realistic target. See Limitations & Lessons Learned below for an honest discussion of what this model can and cannot do.
Source: professional CS2 match history (tier 1–3), covering 6,008 matches / 12,479 played maps across 488 teams and 1,569 players, from Oct 25, 2023 to Nov 7, 2026. Many more matches have a series result (and usually the lineups) but no per-map rows; counting those, there are 11,426 matches (from January 2023), and the player ratings use all of them.
The raw CSVs are included under data/raw/ (CC BY-SA 4.0, see Data source).
To refresh the data, download the latest version from Kaggle and replace these files:
cs2_all_tiers_games.csv,cs2_tier1_games.csv,cs2_tier2_games.csv,cs2_tier3_games.csvteams.csv,players.csv,tournaments.csv
All features are computed to be strictly leakage-free: every rolling/expanding statistic for a given match uses only data from strictly earlier matches. This required special care because every map within the same best-of series shares an identical timestamp in the source data — naive chronological sorting alone is not enough to prevent leakage across maps of the same series.
| Group | Description |
|---|---|
| Player Rating | Each player's own strength rating; team strength = average of the lineup (see below) |
| Team Form | Win rate over the last 5 matches |
| Head-to-Head | Historical win rate between the two specific teams |
| Player Firepower | Rolling ADR / KAST of the starting roster, and the roster's average experience |
| Map-specific Elo | Separate Elo rating per (team, map) pair, and the team's experience on that map |
| Rest Days | Days since the team's previous match |
| Win/Loss Streak | Current signed momentum streak |
| Roster Stability | Player overlap with the team's previous match roster |
The model uses 28 numeric features built from these groups (mostly each team's value and the difference between the two). Earlier versions also had a team Elo, form over the last 10 / all matches, win rate on the map and a K–D difference form; with the player rating in place they added nothing measurable and were dropped.
Player rating. A team name is a weak identity: a roster that moves to a new organisation would start from scratch, and a team that keeps its name after replacing most of its players would keep its old rating. So instead of a team Elo, every player has a Glicko rating with an uncertainty that shrinks as they play and grows while they're inactive (so new and returning players' ratings move faster), and a team's strength is the average rating of the players in its lineup. Each map is a separate result, weighted by its round difference (a 13-2 counts more than a 13-11); matches without per-map rows count by their series score. Lineups come from the map rows, or from the match's overall stats row when map rows are missing. If none of a team's players is known, its team-name Elo is used instead.
├── data/
│ ├── raw/ # input CSVs from Kaggle
│ └── processed/ # cleaned parquet files (the API reads three of them)
├── src/
│ ├── eda_cleaning.py # step 1: cleaning & validation
│ ├── pipeline.py # step 2: feature engineering
│ ├── player_rating.py # player ratings (team strength = lineup average)
│ ├── train.py # step 3: model training & calibration
│ ├── map_context.py # each team's state on every pool map at a given time
│ ├── veto.py # map veto model (which maps come up)
│ ├── series.py # series probability + its evaluation
│ ├── predict.py # step 4: inference
│ └── symmetry.py # team-order invariance (shared by train & predict)
├── api/
│ └── main.py # FastAPI service
├── web/
│ ├── index.html # single-page UI served at /
│ └── docs.html # API docs served at /docs
├── tests/
│ └── test_train_serve_parity.py # live features == training features
├── deploy/
│ ├── huggingface/
│ │ └── README.md # Hugging Face Space config (front matter)
│ └── supabase/
│ ├── predictions_rls.sql # insert-only access to the predictions table
│ └── series_predictions.sql # series_predictions table + insert-only access
├── models/ # trained model artifacts + metadata
├── Dockerfile # API + UI image (serve-only dependencies)
├── requirements.txt # full: pipeline + training + API
├── requirements-serve.txt # API only
└── env.example
pip install -r requirements.txtCopy env.example to .env and fill in your Supabase project URL and publishable key
(Project Settings → API). Logging is optional; see Prediction logging.
Each stage must be run in order — every stage reads the previous stage's output:
# 1. Clean raw CSVs -> data/processed/{maps_clean,matches_summary,match_veto,match_lineups}.parquet
python -m src.eda_cleaning --raw-dir data/raw --output-dir data/processed
# 2. Feature engineering -> data/processed/features_engineered.parquet
python -m src.pipeline --processed-dir data/processed --output-dir data/processed
# 3. Train + calibrate + tune -> models/champion_model.pkl
# (--skip-test: don't score the test period at all; the final model is still fit on all data)
python -m src.train --features-path data/processed/features_engineered.parquet --output-dir models
# 4. Map veto model -> models/veto_model.json (~5 min; uses step 3's split dates)
python -m src.veto
# 5. Evaluate series predictions -> models/series_eval.json
python -m src.series
# 6. Predict from the command line: one map, the likely maps, or maps of your choice
python -m src.predict --team1 "Team Vitality" --team2 "Natus Vincere" --map Mirage
python -m src.predict --team1 "Team Vitality" --team2 "Natus Vincere" --bestof 3
python -m src.predict --team1 "Team Vitality" --team2 "Natus Vincere" --bestof 3 --maps Nuke,Mirage,InfernoWith --maps, list the picks first and the decider last.
src.veto and src.series take --skip-test too. The series effect σ is stored in
models/model_metadata.json together with the map model's version and is kept when the
same model version is retrained; python -m src.series --set-sigma <value> writes a new
one.
uvicorn api.main:app --reload --port 8000Web UI at http://localhost:8000/, API docs with a try-it box at http://localhost:8000/docs (web/docs.html, rendered from /openapi.json).
| Endpoint | Description |
|---|---|
GET / |
Web UI (web/index.html) |
GET /docs |
API docs (web/docs.html) |
GET /health |
Service health check |
GET /api/v1/teams |
Teams that played in the last 120 days of the data (predictions still accept any team in the data) |
GET /api/v1/maps |
Active map pool (maps played in the last 60 days) |
GET /api/v1/model |
Model name, data range and held-out test metrics |
POST /api/v1/predict |
Predict one map; logs to Supabase if configured |
POST /api/v1/predict-series |
Likely maps (or maps you give: picks, then the decider), each map's win probability, series probability and score distribution |
Both prediction endpoints return model_version (currently pg-28), which changes when
the feature set or the rating system changes. Logged predictions carry it in their
model_name (for example Logistic Regression [pg-28]), so they can be matched to the
model that made them.
The API degrades gracefully if Supabase isn't configured — predictions are still
returned, just not logged (logged_to_db: false). Unknown team names and tiers are
rejected with 400 (the CLI still allows cold-start predictions for unseen teams).
The Dockerfile builds a serve-only image: it copies just the champion model, the veto
model and the three parquet files the predictor reads (maps_clean, matches_summary,
match_lineups). Startup takes ~3 s while the history tables and player ratings are built.
The live demo runs on a small VPS (2 vCPU, 4 GB RAM) as a Docker Compose service. The container publishes no ports. A Caddy reverse proxy on the same Docker network forwards the domain to it and gets the HTTPS certificate from Let's Encrypt automatically.
# docker-compose.yml, next to the Dockerfile on the server
services:
fragpredict:
build: .
restart: unless-stopped
env_file: .env
networks:
- proxy
networks:
proxy:
external: true
name: <caddy-network> # the Docker network Caddy runs on# Caddyfile
fragpredict.org {
reverse_proxy fragpredict:7860
}
To deploy a new version (for example after retraining), push it to main and run this
on the server:
cd /opt/fragpredict && git pull && docker compose up -d --buildThe same image also runs as a Docker Space:
pip install -U huggingface_hub
hf auth login
hf repos create <user>/fragpredict --type space --sdk docker
hf upload <user>/fragpredict . . --repo-type space \
--include "Dockerfile" --include "requirements-serve.txt" \
--include "api/*.py" --include "src/*.py" --include "web/*" \
--include "models/champion_model.pkl" --include "models/model_metadata.json" \
--include "models/veto_model.json" \
--include "data/processed/maps_clean.parquet" --include "data/processed/matches_summary.parquet" \
--include "data/processed/match_lineups.parquet"
hf upload <user>/fragpredict deploy/huggingface/README.md README.md --repo-type spaceAfter retraining, rerun the first hf upload to redeploy.
Prediction logging is optional. To turn it on, first run
deploy/supabase/predictions_rls.sql and deploy/supabase/series_predictions.sql in the
Supabase SQL Editor. They give the publishable key (sb_publishable_…) insert-only
access to the predictions and series_predictions tables: no reads, updates or
deletes. Then set SUPABASE_URL and SUPABASE_KEY (the publishable
key): on a server, in the .env file next to docker-compose.yml; on Hugging Face, as
Secrets in the Space settings. Don't use Space Variables, because those are
public. Even if the key leaked, all it could do is insert rows, which the public API
already does.
Two safeguards in the API protect the table, and neither uses IP addresses:
- Write budget: at most 30 rows a minute and 3,000 a day.
- Duplicate check: the same match and map (for series: the same format and maps), in either team order, isn't logged again within 10 minutes.
When a write is skipped, the prediction is still returned; only the log entry is dropped.
Worth being upfront about what this model can't do, not just what it can.
- CS2 is high-variance. A ROC-AUC around 0.65 is a realistic ceiling for this problem, not a shortfall of the modeling approach.
- The live site doesn't know who will play. The player rating needs the lineup, and the lineup of an upcoming match isn't in the data. The site assumes each team's last lineup with at least four known players; for teams without one (172 of the 365 in the team list) it falls back to the team-name Elo. That costs accuracy: on the test period, log loss is 0.6536 with the lineups that actually played and 0.6562 with the assumed ones, against 0.6588 for the previous model. So in the live setting the improvement is about half the measured one, and on its own it can't be told apart from the previous model (−0.0026, 95% CI −0.0072 to +0.0020).
- Calibration drifts over time (concept drift). The scene evolves — rosters change, new teams emerge. A calibration curve fit on one time period will not be perfectly diagonal on a later period. This was measured explicitly (not assumed) and cross-fitted calibration was tested as a potential fix — it did not help, confirming the cause is genuine distribution shift rather than a calibration methodology issue. Practical mitigation: retrain periodically as new data accumulates.
- Old data still helps, despite scene evolution. An empirical test comparing training windows (6/12/18 months vs. full history) showed the full ~2.5-year history outperforms any recency-truncated subset — sample size outweighed staleness for this dataset size. This may change as more data accumulates.
- Two real data-leakage bugs were caught during development (and are worth
naming, since catching them was itself part of the engineering process):
team_idin the source data is not a stable team identity (the same team appears under dozens of different IDs across matches) — team matching had to be done by name instead.- The map-specific Elo implementation initially processed both perspectives of the same match in one loop, causing the second row to read the first row's already-updated rating as if it were pre-match — leaking that match's own outcome. Caught via an implausibly large jump in test ROC-AUC (0.65 → 0.78) and fixed by processing each match exactly once.
- Team order bias (found and fixed). The team1/team2 order in the source data
isn't random — team1 wins ~53% of maps and usually has the higher Elo. A model
trained only in that order learned a ~5-point bonus for "whoever is listed first",
which has no basis in the data: once the features are accounted for, the position
effect is ≈0. Since API/UI users choose the order themselves, the same match got
different predictions depending on order (the favourite flipped in ~15% of test
matches). The fix (
src/symmetry.py): each split is augmented with mirrored rows (teams swapped, label flipped) after splitting, and every prediction averages both orders, so P(A beats B) + P(B beats A) = 1 exactly. The model's own inconsistency before averaging dropped from 6.1 to 1.9 points, and test log loss improved from 0.6614 (old model, random user order) to 0.6576. Fixing the order canonically instead (alphabetical, or higher Elo first) also removes the order dependence but wasn't more accurate. - The choice between models was noise, so the simplest one won. The champion used to be picked by test-set log loss and then scored on that same test set — a mild selection bias (on average it flattered the reported log loss by 0.0008, at most 0.0025). It's now picked on the validation period. Re-running the comparison with 10 seeds showed the gradient-boosted models trading places from seed to seed (XGBoost won validation in 7 runs, CatBoost in 3), with every pairwise difference inside its bootstrap CI. Logistic regression had the best validation log loss in all 10 runs, is deterministic and is as good as the best tree model on test, so it is the champion: with the current features, gradient boosting finds no extra non-linear signal. The selection rule stays model-agnostic, so a tree model takes over if future features give it something to find. Side effect: logistic regression uses only the numeric features, so tier and best-of don't change a prediction (under order invariance they could only matter through interactions). The map still matters through map-specific Elo and experience.
- The veto model knows which maps are likely, not the exact lineup. Its most likely 3
maps come up together about 1 time in 6. That's five times more often than chance, and
the probability it states matches how often it happens. Single maps are easier: the
model's favourite map is in the lineup about two times in three.
- Simple rule: adding each map's 90-day play share for the two teams does almost as well at naming the played maps. The model is 1–2 points ahead, and the 95% CI includes 0.
- Bo1: with only 99 / 127 matches, the leftover-map probabilities were overconfident on validation (32% stated, 19% observed) but on target on test (29% / 28%).
- Which maps come up barely changes who wins the series. Weighting all 7 maps equally predicts the series winner as well as the veto model's weights (slightly better on test). Even knowing the maps that were actually played doesn't help. The reason is that a team's win probability barely changes from map to map: the actual maps move it by a median of less than 1 point.
- Map probabilities are pre-series estimates. Because the maps of a series are linked (see Map veto and series), each map's probability is the estimate before the series starts. If a Bo3 reaches 1-1, the decider is usually slightly closer to 50% than shown; the API doesn't return that conditional probability. The series effect fixes the share of 3-map series, but its gain on the full score distribution is small and within noise (test score log loss −0.0036, 95% CI −0.0090 to +0.0023).
- Not predicted: map order and who picked what. Which team starts the veto isn't in the data, so whether a pick is map 1 or map 2 is a coin flip. Which team picked a map can't be told apart either. "Teams pick their own strong maps" and "teams pick to deny the opponent" fit the played maps exactly equally well, because the likelihood is symmetric. The model takes the first reading as a convention. A first fit got stuck in a worse local optimum with the picks reversed; fitting from several starting points fixed that.
- 967 Bo3 matches with missing map rows are left out of the veto model (the map model still uses them).
- Tested but not adopted (negative results, kept for transparency): recency-weighted training samples, wider Optuna search (100 trials), and Optuna-tuned CatBoost all underperformed their simpler counterparts on the held-out test set — with a validation set of ~1,600 rows, aggressive hyperparameter search tends to overfit to validation noise rather than improve generalization.
The dataset is Counter-Strike Pro Matches on Kaggle
by ektarr, licensed
CC BY-SA 4.0. A copy of the CSVs
is included under data/raw/; the Kaggle page has the latest version.
This repository and the live demo also ship processed files derived from it
(maps_clean.parquet, matches_summary.parquet, features_engineered.parquet,
match_veto.parquet and match_lineups.parquet: cleaned and restructured per match and
map). Under the ShareAlike term, those files are
licensed CC BY-SA 4.0 as well.
The code is released under the MIT License.
The data is licensed separately: the Kaggle CSVs under data/raw/ and the processed
files derived from them under data/processed/ are CC BY-SA 4.0 (see
Data source), not MIT.