AIFootballPredictions
AIFootballPredictions is an ML-based system to predict if a football match will have over 2.5 goals. Using historical data from top European leagues (Serie A, EPL, Bundesliga, La Liga, Ligue 1), it employs advanced feature engineering and model training techniques to provide accurate predictions. Perfect for sports analytics enthusiasts.
Install / Use
/learn @MauroAndretta/AIFootballPredictionsREADME
AIFootballPredictions
🎯 AI Football Predictions: Will There Be Over 2.5 Goals? 🎯
Check out the latest predictions for the upcoming football matches! We've analyzed the data and here are our thoughts: PREDICTIONS DONE: 2025-02-28
Premier League:
Serie A:
- ⚽ Fiorentina 🆚 Lecce: Under 2.5 Goals (59.89% chance)
- ⚽ Atalanta 🆚 Venezia: Over 2.5 Goals! 🔥 (85.17% chance)
- ⚽ Napoli 🆚 Inter: Over 2.5 Goals! 🔥 (94.92% chance)
- ⚽ Udinese 🆚 Parma: Over 2.5 Goals! 🔥 (75.26% chance)
- ⚽ Monza 🆚 Torino: Over 2.5 Goals! 🔥 (77.75% chance)
- ⚽ Bologna 🆚 Cagliari: Under 2.5 Goals (76.23% chance)
- ⚽ Genoa 🆚 Empoli: Under 2.5 Goals (78.29% chance)
- ⚽ Roma 🆚 Como: Over 2.5 Goals! 🔥 (50.44% chance)
- ⚽ Milan 🆚 Lazio: Under 2.5 Goals (54.49% chance)
- ⚽ Juventus 🆚 Verona: Under 2.5 Goals (88.96% chance)
Bundesliga:
- ⚽ Stuttgart 🆚 Bayern Munich: Over 2.5 Goals! 🔥 (90.58% chance)
- ⚽ St Pauli 🆚 Dortmund: Under 2.5 Goals (78.8% chance)
- ⚽ Bochum 🆚 Hoffenheim: Over 2.5 Goals! 🔥 (76.12% chance)
- ⚽ Werder Bremen 🆚 Wolfsburg: Under 2.5 Goals (81.46% chance)
- ⚽ RB Leipzig 🆚 Mainz: Over 2.5 Goals! 🔥 (87.95% chance)
- ⚽ Heidenheim 🆚 M'gladbach: Over 2.5 Goals! 🔥 (68.89% chance)
- ⚽ Ein Frankfurt 🆚 Leverkusen: Under 2.5 Goals (61.12% chance)
- ⚽ Union Berlin 🆚 Holstein Kiel: Over 2.5 Goals! 🔥 (91.03% chance)
- ⚽ Augsburg 🆚 Freiburg: Over 2.5 Goals! 🔥 (57.77% chance)
La Liga:
- ⚽ Valladolid 🆚 Las Palmas: Under 2.5 Goals (94.32% chance)
- ⚽ Girona 🆚 Celta: Over 2.5 Goals! 🔥 (73.47% chance)
- ⚽ Vallecano 🆚 Sevilla: Over 2.5 Goals! 🔥 (88.3% chance)
- ⚽ Betis 🆚 Real Madrid: Over 2.5 Goals! 🔥 (94.72% chance)
- ⚽ Ath Madrid 🆚 Ath Bilbao: Over 2.5 Goals! 🔥 (94.72% chance)
- ⚽ Leganes 🆚 Getafe: Over 2.5 Goals! 🔥 (65.62% chance)
- ⚽ Barcelona 🆚 Sociedad: Over 2.5 Goals! 🔥 (72.24% chance)
- ⚽ Mallorca 🆚 Alaves: Under 2.5 Goals (99.17% chance)
- ⚽ Osasuna 🆚 Valencia: Over 2.5 Goals! 🔥 (63.72% chance)
- ⚽ Villarreal 🆚 Espanol: Over 2.5 Goals! 🔥 (89.97% chance)
Ligue 1:
- ⚽ Monaco 🆚 Reims: Over 2.5 Goals! 🔥 (73.58% chance)
- ⚽ St Etienne 🆚 Nice: Under 2.5 Goals (93.4% chance)
- ⚽ Lens 🆚 Le Havre: Over 2.5 Goals! 🔥 (65.85% chance)
- ⚽ Paris SG 🆚 Lille: Over 2.5 Goals! 🔥 (66.92% chance)
- ⚽ Lyon 🆚 Brest: Over 2.5 Goals! 🔥 (92.07% chance)
- ⚽ Montpellier 🆚 Rennes: Over 2.5 Goals! 🔥 (76.95% chance)
- ⚽ Auxerre 🆚 Strasbourg: Under 2.5 Goals (70.88% chance)
- ⚽ Angers 🆚 Toulouse: Over 2.5 Goals! 🔥 (78.66% chance)
- ⚽ Marseille 🆚 Nantes: Under 2.5 Goals (56.8% chance)
Table of Contents
- Project Overview
- Directory Structure
- Setup and Installation
- Data Acquisition
- Data Preprocessing
- Model Training
- Upcoming Matches Acquisition
- Making Predictions
- Supported Leagues
- Contributing
- License
- Disclaimer
Project Overview
AIFootballPredictions aims to create a predictive model to forecast whether a football match will exceed 2.5 goals. The project is divided into four main stages:
- Data Acquisition: Download and merge historical football match data from multiple European leagues.
- Data Preprocessing: Process the raw data to engineer features, handle missing values, and select the most relevant features.
- Model Training: Train several machine learning models, perform hyperparameter tuning, and combine the best models into a voting classifier to make predictions.
- Making Predictions: Use the trained models to predict outcomes for upcoming matches and generate a formatted message for sharing.
Directory Structure
The project is organized into the following directories:
└─── `AIFootballPredictions`
├─── `conda`: all the conda environemnts
├─── `data`: the folder for the data
│ ├─── `processed`
│ └─── `raw`
├─── `models`: the folder with the saved and trained models
├─── `notebooks`: all the notebooks if any
└─── `scripts`: all the python scripts
├─── `data_acquisition.py`
├─── `data_preprocessing.py`
├─── `train_models.py`
├─── `acquire_next_matches.py`
└─── `make_predictions.py`
Key Scripts
data_acquisition.py: Downloads and merges football match data from specified leagues and seasons.data_preprocessing.py: Preprocesses the raw data, performs feature engineering, and selects the most relevant features.train_models.py: Trains machine learning models, performs hyperparameter tuning, and saves the best models.acquire_next_matches.py: Acquires the next football matches data, updates team names using a mapping file, and saves the results to a JSON file.make_predictions.py: Uses the trained models to predict outcomes for upcoming matches and formats the results into a readable txt message.
Note: it is suggested to avoid path error, to execute all the scripts in the root folder.
Setup and Installation
To set up the environment for this project, follow these steps:
-
Clone the repository:
git clone https://github.com/yourusername/AIFootballPredictions.git cd AIFootballPredictions -
Create a conda environment
conda env create -f conda/aifootball_predictions.yaml conda activate aifootball_predictions
Data Acquisition
To download and merge football match data, run the data_acquisition.py script:
python scripts/data_acquisition.py --leagues E0 I1 SP1 F1 D1 --seasons 2425 2324 2223 --raw_data_output_dir data/raw
This script downloads match data from football-data.co.uk for the specified leagues and seasons, merges them, and saves the results to the specified output directory.
To avoid error please see the Supported Leagues sections.
Data Preprocessing
Once the raw data is downloaded, preprocess it by running the data_preprocessing.py script:
python scripts/data_preprocessing.py --raw_data_input_dir data/raw --processed_data_output_dir data/processed --num_features 20 --clustering_threshold 0.5
This script processes each CSV file in the input folder, performs feature engineering, selects relevant features while addressing feature correlation, handles missing values, and saves the processed data.
Model Training
To train machine learning models and create a voting classifier, use the train_models.py script:
python scripts/train_models.py --processed_data_input_dir data/processed --trained_models_output_dir models --metric_choice accuracy --n_splits 10 --voting soft
This script processes each CSV file individually, trains several machine learning models, performs hyperparameter tuning, combines the best models into a voting classifier, and saves the trained voting classifier for each league.
Upcoming Matches Acquisition
To acquire the next football matches data and update the team names, run the acquire_next_matches.py script:
python scripts/acquire_next_matches.py --get_teams_names_dir data/processed --next_matches_output_file data/next_matches.json
This script will:
- Fetch the next matches data from the football-data.org API.
- Read the unique team names from the processed data files.
- Update the team names in the next matches data using the mapping file.
- This step is necessary because the teams' names acquired with the football-data.org API differ from the teams' names acquired from football-data.co.uk, which've been used to train the ML models.
- Save the updated next matches to a JSON file.
Setu up the API_KEY
In order to properly execute the acquire_next_matches.py script it is first necessary to set up the API_KEY to gather the next matches information. Below the procedure on how to properly set up the variable:
-
Register for an API Key:
- Go to the Football-Data.org website and register to get your personal API key.
-
Create a
~/.envFile:- This file will be used by the
load_dotenvlibrary to set up theAPI_FOOTBALL_DATAenvironment variable. - To create the file:
- Open your terminal and run the command:
vim ~/.env - This will create a new
~/.envfile if it doesn't already exist.
- Open your terminal and run the command:
- This file will be used by the
-
Insert the API Key:
- After running the
vimcommand, press theikey (for "insert mode"). - Write down the following line, replacing
your_personal_keywith your actual API key:API_FOOTBALL_DATA=your_personal_key
- After running the
-
Save and Exit:
- Press the
Esckey to exit insert mode. - Then, type
:wq!and pressEnterto save the changes and exit the editor.
- Press the
-
Verify the Variable:
- To check if the variable has been properly set, run the following command from the terminal:
cat ~/.env
- You should see the
API_FOOTBALL_DATAvariable listed with your API key.
- To check if the variable has been properly set, run the following command from the terminal:
Making Predictions
To predict the outcomes for upcoming matches and generate a formatted message for sharing, run the make_predictions.py script:
python scripts/make_predictions.py --models_dir models --data_dir data/processed --output_file final_predictions.txt --json_competitions data/next_matches.json
This script will:
- Load the pre-trained
Related Skills
feishu-drive
349.2k|
things-mac
349.2kManage Things 3 via the `things` CLI on macOS (add/update projects+todos via URL scheme; read/search/list from the local Things database)
clawhub
349.2kUse the ClawHub CLI to search, install, update, and publish agent skills from clawhub.com
codebase-memory-mcp
1.2kHigh-performance code intelligence MCP server. Indexes codebases into a persistent knowledge graph — average repo in milliseconds. 66 languages, sub-ms queries, 99% fewer tokens. Single static binary, zero dependencies.
