{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreiajxqqpkwuqykmp2tsie5vbo74t74lkhmqa3lrb6wjpdr5hejbg5u",
"uri": "at://did:plc:25rdn5elo5izoxrmtis34zuk/app.bsky.feed.post/3mositby3vbr2"
},
"coverImage": {
"$type": "blob",
"ref": {
"$link": "bafkreig7yi4ezklnsvi5qdzmtedznu4tqzp7qrdjybxibs4mu7r6vo53cm"
},
"mimeType": "image/webp",
"size": 70980
},
"path": "/vesna123best/-i-built-a-world-cup-2026-prediction-pipeline-with-sportmicro-python-and-github-actions-4h03",
"publishedAt": "2026-06-21T13:27:25.000Z",
"site": "https://dev.to",
"tags": [
"python",
"api",
"opensource",
"machinelearning",
"@sportmicro"
],
"textContent": "I wanted a football prediction project that felt closer to a real data product than a one-off notebook.\n\nSo I built a pipeline that:\n\n * pulls World Cup and national-team data from Sportmicro\n * engineers match and team-form features\n * trains a hybrid prediction model\n * generates upcoming fixture predictions and provisional title odds\n * exports machine-readable outputs\n * can refresh itself on a schedule through GitHub Actions\n\n\n\nThe repo is here:\n\n`world-cup-2026-prediction-sportmicro-api`\n\n## What problem I was trying to solve\n\nA lot of sports prediction demos stop at one model and one CSV. That is fine for experimentation, but it breaks down quickly if you want something you can rerun, automate, or publish.\n\nFor this project, I wanted a workflow that could:\n\n 1. discover the relevant World Cup league data dynamically\n 2. combine tournament history with recent national-team form\n 3. train models from cached data\n 4. generate fresh outputs without manual cleanup\n 5. fit naturally into CI/CD\n\n\n\nThe result is a small but production-style sports analytics pipeline.\n\n## The stack\n\n * Python for data fetching, feature engineering, training, and reporting\n * `scikit-learn` for classification and score expectation models\n * `pandas` and `numpy` for the data layer\n * Node.js only where it adds value: generating Sportmicro endpoint paths through the official `@sportmicro/endpoint` package\n * GitHub Actions for scheduled refreshes\n\n\n\nThat Python + Node split is deliberate. The modeling and orchestration live in Python, while the API query construction stays aligned with Sportmicro's official endpoint builder.\n\n## Why the Sportmicro integration is interesting\n\nInstead of hardcoding raw query strings, the repo sends a JSON request spec from Python to a Node helper script, and the helper builds the final endpoint path using `@sportmicro/endpoint`.\n\nThat means filters like `eq`, `gte`, `in(...)`, pagination, and ordering are all constructed in a consistent way.\n\nThis is the part I like most architecturally: Python stays clean, and the final URL generation still uses the official tooling intended for the API.\n\nExample shape of the workflow:\n\n\n\n python -m wc2026_predictor run-all\n\n\nUnder the hood, that flow:\n\n 1. discovers the World Cup league id\n 2. downloads seasons and historical World Cup matches\n 3. pulls recent national-team matches\n 4. trains the models\n 5. predicts future World Cup fixtures\n 6. writes reports and CSV/JSON outputs\n\n\n\n## How the model works\n\nThis is not a single-model predictor.\n\nThe repo uses a layered approach:\n\n * Elo-style team strength updates\n * rolling form features from recent matches\n * a `RandomForestClassifier` for match outcome classification\n * two `PoissonRegressor` models for expected home and away goals\n * a hybrid ensemble that blends ML probabilities, Elo expectation, and Poisson-derived outcome probabilities\n\n\n\nI used this design because football is noisy. A pure classifier can miss score dynamics, and a pure Poisson model can miss richer recent-form patterns. Combining them gives a more balanced prediction layer.\n\n## What the pipeline outputs\n\nEach run produces artifacts that are useful both for people and for downstream systems:\n\n * `predictions/latest_match_predictions.csv`\n * `predictions/latest_match_predictions.json`\n * `predictions/title_odds.csv`\n * `predictions/title_odds.json`\n * `predictions/report.md`\n\n\n\nThe match predictions include:\n\n * predicted result\n * home/draw/away probabilities\n * expected goals\n * most likely scoreline\n\n\n\nThe title odds are intentionally labeled as provisional when the full tournament structure is not yet available from the API.\n\n## A small detail that matters: automation\n\nI also wired the repo to run through GitHub Actions on a schedule and by manual dispatch.\n\nThe workflow:\n\n * installs Python and Node\n * installs dependencies\n * runs the full prediction pipeline\n * commits refreshed outputs back into the repository\n\n\n\nThat turns the project from \"interesting code\" into something that can act like a living forecast feed.\n\n## Project structure\n\n\n world-cup-2026-prediction-sportmicro-api/\n ├─ .github/workflows/automation.yml\n ├─ scripts/build_endpoint.mjs\n ├─ scripts/run_pipeline.ps1\n ├─ src/wc2026_predictor/\n │ ├─ cli.py\n │ ├─ endpoint_builder.py\n │ ├─ features.py\n │ ├─ modeling.py\n │ ├─ pipeline.py\n │ ├─ reporting.py\n │ └─ sportmicro.py\n ├─ data/\n ├─ artifacts/\n └─ predictions/\n\n\nI tried to keep the boundaries clean:\n\n * `sportmicro.py` handles API access and normalization\n * `features.py` builds the training and fixture frames\n * `modeling.py` owns training and prediction logic\n * `pipeline.py` orchestrates the end-to-end flow\n * `reporting.py` turns outputs into a readable Markdown report\n\n\n\n## Running it locally\n\nSetup is straightforward:\n\n\n\n npm install\n python -m pip install --upgrade pip\n python -m pip install .[dev]\n\n\nThen create `.env` from `.env.example` and set your API key:\n\n\n\n SPORTMICRO_API_KEY=your_sportmicro_api_key_here\n SPORTMICRO_BASE_URL=https://football.sportmicro.com\n WC2026_PREDICTION_START_DATE=2026-01-01\n WC2026_RECENT_MATCH_START_DATE=2021-01-01\n\n\nRun the full workflow:\n\n\n\n python -m wc2026_predictor run-all\n\n\nOr use the PowerShell wrapper:\n\n\n\n ./scripts/run_pipeline.ps1\n\n\n## What I would improve next\n\nThere is still plenty of room to push this further:\n\n * add probability calibration analysis\n * bring in more match-statistics features\n * simulate bracket progression once full 2026 structure is available\n * publish a small dashboard on top of the generated outputs\n\n\n\nThose are the kinds of upgrades that would move the project from \"useful forecasting repo\" to \"full sports analytics product.\"\n\n## Final thought\n\nThe part I care about most in projects like this is not just prediction accuracy. It is whether the system is structured well enough to rerun, inspect, automate, and extend.\n\nThat was the goal here: build a World Cup 2026 prediction repo that is practical, composable, and easy to evolve.\n\nIf you are building in sports analytics, APIs, or ML pipelines, I think this pattern is more useful than another isolated notebook.\n\nIf you want, I can also turn this into:\n\n * a shorter dev.to version with a more punchy hook\n * a more SEO-focused version\n * a version written in a more personal \"build in public\"\n\n",
"title": "I Built a World Cup 2026 Prediction Pipeline with Sportmicro, Python, and GitHub Actions"
}