Skip to main content

ApexGrid

Formula 1 race outcome prediction engine using FastF1 telemetry, a calibrated ML ensemble, and 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 40 configured race-pace and degradation features (stage-gated from 15 at pre_fp1 up to 40 at after_qualifying), blends a 3-way ML ensemble (Random Forest, XGBoost, Ridge), and runs vectorized Monte Carlo race simulations (10,000 default draws / 25,000 precision mode) under strict stage-gated temporal cutoffs.

FastF1 / OpenF1 ──► Feature Engineering ──► ML Ensemble ──► Vectorized Monte Carlo ──► Predictions
  (FP1–Quali)       (40 features, gated)   (RF+XGB+Ridge)    (10k–25k: DNF, SC)       (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.
  • Vectorized Monte Carlo (10,000 default / 25,000 precision): Residual-calibrated pace variance, empirical DNF hazard draws, venue-specific Safety Car disruption priors, and opt-in wet-weather / pit-strategy sub-models (capabilities in model_config.json).
  • Walk-Forward Validation: Expanding-window chronological validation ({1…r−1} → r) with out-of-fold MAE, Spearman, Brier Score, and Ranked Probability Score (RPS). 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)

Install the package:

pip install apexgrid

Upgrade to the latest release:

pip install --upgrade --no-cache-dir apexgrid

Launch 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 -e ".[dev]"

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 --cache --preview
apexgrid clean --cache --force

Disposable caches live under the configured paths.cache_dir (default: data/cache). Calendar schedules, starting-grid retrievals, and FastF1 HTTP responses use separate calendar/, grids/, and fastf1/ namespaces. Collected session CSVs remain durable datasets under data/raw; cleaning the cache does not delete those datasets or official starting-grid manifests.


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 and apply a 0.5x provisional_grid_discount to circuit grid weights when using provisional_grid_position (re-normalizing $w_{\text{ml}} = 1.0 - w_{\text{grid}}$, or disabling blending $w_{\text{grid}} = 0$, $w_{\text{ml}} = 1$ when no grid is available); verified pre-2018 starting grids use a 0.75 / 0.25 override.

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) $$

Sparse grids ($n < 20$) scale $\sigma$ proportionally down to a 1.20 floor, and constructors with $\ge 8$ out-of-fold residuals use shrunk team volatility $\text{clip}(0.70 \cdot \sigma_{\text{team}} + 0.30 \cdot \sigma_{\text{global}},, 1.20,, 1.5 \cdot \sigma_{\text{global}})$. When weather_aware_prediction is enabled in model_config.json, wet-weather draws scale volatility by 1.35×, Safety Car probability by 1.40×, and DNF hazard by 1.40× (capped at 0.35 for scalar fallback). By default, race_pace_intelligence and race_control_model are active while tire_degradation_modeling, pit_strategy_simulator, and weather_aware_prediction are opt-in (false).

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) alongside ExpFinishClassified (mean finish across non-DNF runs).
  • Walk-Forward Guard: Any failed validation fold transitions status to BLOCKED and clears residual arrays.

Configuration

File Purpose
src/apexgrid/config/model_config.json Ensemble weights, hyperparameters, feature sets, topology blending
src/apexgrid/config/tracks.json 23 championship circuits, lengths, types, calendar rounds
src/apexgrid/config/strategy_config.json Tire compounds, pit loss times, 23 circuit strategy priors
src/apexgrid/config/settings.json Raw/processed data paths, cache directory, and output directory

Testing

219+ tests across test_*.py files (215+ fast tests + 4 @pytest.mark.slow tests):

pytest -m "not slow" -q   # fast inner-loop suite
pytest -q                 # full suite
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.1.2

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.1.2
File Size Uploaded Provenance Actions
apexgrid-1.1.2.tar.gz 344.2 kB Without provenance Details for apexgrid-1.1.2.tar.gz

Built distribution (wheel)

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

Total release size: 674.4 kB

Release files / apexgrid-1.1.2.tar.gz

Download URL apexgrid-1.1.2.tar.gz
Size 344.2 kB
Tags Source
SHA-256 checksum
How to use checksums
396777a56e65e816ea3b3678e6f16e437cf8342a72cf32af0df95d127ae4cb05
BLAKE2b-256 checksum
How to use checksums
957c1fc5457fb385cf815827bc87e3ee332cda660e703d9aed40441813ae0866
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.17

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

Download URL apexgrid-1.1.2-py3-none-any.whl
Size 330.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
450f38d5c6fdd61fe3cc40323d5f4e90afe28d608cb99b0f1f017d0f1ae89e8e
BLAKE2b-256 checksum
How to use checksums
8079f1f125d33d3f0a66fda1a5cc56b67b765b5943a370d12694073412c2d41b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.17

Security for apexgrid 1.1.2

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