Skip to main content

ApexGrid

Formula 1 race outcome prediction engine using FastF1 telemetry, a calibrated ML ensemble, and 25,000-iteration Monte Carlo simulation.

PyPI Version Python License: MIT Tests


ApexGrid forecasts finishing positions, win probabilities, and podium chances across all 23 Formula 1 championship rounds. It ingests practice and qualifying telemetry via FastF1 and OpenF1, builds 25+ race-pace and degradation features, blends a 3-way ML ensemble (Random Forest, XGBoost, Ridge), and runs 25,000 Monte Carlo race simulations under strict stage-gated temporal cutoffs.

FastF1 / OpenF1 ──► Feature Engineering ──► ML Ensemble ──► 25,000 Monte Carlo ──► Predictions
  (FP1–Quali)         (25+ features)       (RF+XGB+Ridge)    (DNF, SC, weather)     (Win%, Podium%, EF)

Contents


Capabilities

  • 3-Way ML Ensemble: 40% Random Forest + 30% XGBoost + 30% Ridge Regression, calibrated via chronological walk-forward validation. Supports 2-way hybrid (60/40 RF/XGB) and custom weight splits.
  • Circuit-Aware Grid Blending: Adjusts grid vs. ML weights by circuit topology: street (50/50), permanent (35/65), temporary (45/55).
  • Stage-Gated Anti-Leakage: Seven temporal cutoffs (pre_fp1 through after_qualifying) block future-session qualifying or race data from leaking into earlier forecasts.
  • 25,000-Run Monte Carlo: Residual-calibrated pace variance, empirical DNF hazard draws, wet-skill scaling, and venue-specific Safety Car disruption priors.
  • Walk-Forward Validation: Expanding-window chronological validation ({1…r−1} → r). Shuffled k-fold is disabled.
  • Historical Analytics (1950–2026): 11 CLI modules covering driver stats, teammate H2H, qualifying, race craft, circuits, standings, sessions, dominance, records, reliability, and eras.

Installation

End Users (PyPI)

pip install apexgrid
apexgrid

Bundled configurations load from the package; caches and outputs are stored in ~/.apexgrid/.

Developers (Editable)

git clone https://github.com/dineshdhayfule/F1-Race-Predictions.git
cd F1-Race-Predictions
python -m venv .venv
source .venv/bin/activate  # Windows: .venv\Scripts\Activate.ps1
pip install -r requirements.txt
pip install -e .

Both apexgrid and python main.py work inside the cloned repository.


CLI Reference

Predict

apexgrid predict --track monza --year 2026 --stage pre_fp1 --model ensemble
apexgrid predict --track silverstone --year 2026 --stage after_qualifying
apexgrid predict --track monaco --year 2026 --stage after_fp3 --model ensemble --enhanced
apexgrid predict --track baku --year 2026 --stage after_qualifying --model hybrid --rf-weight 70 --xgb-weight 30
apexgrid circuits

Validate & Evaluate

apexgrid evaluate --track sepang --year 2026
apexgrid validate --track baku --year 2026 --stage after_qualifying

History

apexgrid history

Subcommands: driver · h2h · qualifying · race · circuit · standings · session · dominance · records · reliability · eras

Data & Cache

apexgrid collect --year 2026
apexgrid clean --target cache --preview
apexgrid clean --target cache --force

Interactive Menu

Run apexgrid (or python main.py) with no arguments to open the 8-option terminal menu:

# Workflow Scope
1 Predict a Race Circuit, stage, model, and simulation
2 Load / Collect Data FastF1 practice, qualifying, and race ingestion
3 Evaluate a Prediction Score forecasts against official classifications
4 View Previous Predictions Inspect saved CSV tables and Markdown reports
5 Historical Statistics 11 analytics modules (1950–2026)
6 System Health Dependency, config, and dataset checks
7 Configuration Circuit parameters and model settings
8 Data Management Preview and prune cached files

Methodology

Mathematical Formulation & Validation Rules

Stage-Gated Grid Blending

Post-qualifying runs blend official FIA starting grids with ML pace scores by circuit type:

$$ \text{Score}{\text{blended}} = w{\text{ml}} \cdot \text{Score}{\text{ML}} + w{\text{grid}} \cdot \text{Grid}_{\text{actual}} $$

Circuit Type $w_{\text{grid}}$ $w_{\text{ml}}$ Examples
Street 0.50 0.50 Monaco, Baku, Singapore
Permanent 0.35 0.65 Spa, Monza, Silverstone
Temporary 0.45 0.55 Melbourne, Montreal

Pre-qualifying runs mask grid data to NaN, using provisional ML qualifying forecasts (~P1, ~P2) or disabling blending ($w_{\text{grid}} = 0$, $w_{\text{ml}} = 1$).

Residual-Calibrated Pace Volatility

Monte Carlo pace variance is calibrated from walk-forward residuals via Median Absolute Deviation:

$$ \sigma = \max!\left(1.5,; 1.4826 \cdot \text{MAD}(\text{residuals})\right) $$

Wet-weather draws scale volatility by 1.35× and DNF hazard by 1.40×.

Decoupled Modeling & Ranking

  • Two-Stage Separation: Regressors train only on classified finishers; DNF hazards are sampled via binomial draws in Monte Carlo.
  • EWMA Form: Driver and constructor form uses $\alpha = 0.30$ exponential decay.
  • Dual-View Output: Podium banner sorts by Win% ↓, Top3% ↓, ExpectedFinish ↑; full table sorts by DNF-adjusted ExpectedFinish (+1000.0 penalty for non-finishers).
  • Walk-Forward Guard: Any failed validation fold transitions status to BLOCKED and clears residual arrays.

Configuration

File Purpose
config/model_config.json Ensemble weights, hyperparameters, feature sets, topology blending
config/tracks.json 23 championship circuits, lengths, types, calendar rounds
config/strategy_config.json Tire compounds, pit loss times, 15 circuit strategy priors
config/settings.json Cache paths, logging, output directories

Testing

183 tests across 21 modules:

pytest -q
pytest tests/test_walk_forward.py
pytest tests/test_core_features.py
pytest tests/test_dynamic_roster.py
pytest tests/test_weekend_only_pipeline.py

License

MIT

Metadata

Release files for apexgrid 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for apexgrid 1.0.1
File Size Uploaded Provenance Actions
apexgrid-1.0.1.tar.gz 275.7 kB Without provenance Details for apexgrid-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for apexgrid 1.0.1
File Interpreter ABI Platform Actions
apexgrid-1.0.1-py3-none-any.whl Python 3 none any Details for apexgrid-1.0.1-py3-none-any.whl

Total release size: 560.9 kB

Release files / apexgrid-1.0.1.tar.gz

Download URL apexgrid-1.0.1.tar.gz
Size 275.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c6becf57aa7bba086d0b3a22a45d5bcb9534eb8f2327bdfedb2b6bda4210965e
BLAKE2b-256 checksum
How to use checksums
434413a404d33deb1da59babb0fce6b3a15a5d4df185f77018a920852d4e31d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Release files / apexgrid-1.0.1-py3-none-any.whl

Download URL apexgrid-1.0.1-py3-none-any.whl
Size 285.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
abfbff243bf193850f5a7629eaa3e771b4fd42f4410089a96d07a18ebbe8f8e6
BLAKE2b-256 checksum
How to use checksums
0ee29b6c2fe0efcc081efd394cb10d7faedc956b0e8616fc9f2d934e5f0bfc9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Security for apexgrid 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page