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.
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)
- โฝ 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)
- โฝ 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)
- โฝ 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
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
โโโโ acquirenextmatches.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.acquirenextmatches.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.
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/dataacquisition.py --leagues E0 I1 SP1 F1 D1 --seasons 2425 2324 2223 --rawdataoutputdir 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/datapreprocessing.py --rawdatainputdir data/raw --processeddataoutputdir data/processed --numfeatures 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/trainmodels.py --processeddatainputdir data/processed --trainedmodelsoutputdir models --metricchoice 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 acquirenextmatches.py script:
python scripts/acquirenextmatches.py --getteamsnamesdir data/processed --nextmatchesoutputfile 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.
- Save the updated next matches to a JSON file.
Setu up the API_KEY
In order to properly execute the acquirenextmatches.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:
- Create a
~/.envFile:
loaddotenv library to set up the APIFOOTBALL_DATA environment variable.
- To create the file:
- Open your terminal and run the command: vim ~/.env
- This will create a new ~/.env file if it doesn't already exist.
- Insert the API Key:
vim command, press the i key (for "insert mode").
- Write down the following line, replacing yourpersonalkey with your actual API key:
- APIFOOTBALLDATA=yourpersonalkey
- Save and Exit:
Esc key to exit insert mode.
- Then, type :wq! and press Enter to save the changes and exit the editor.
- Verify the Variable:
cat ~/.env
- You should see the APIFOOTBALLDATA variable listed with your API key.
Making Predictions
To predict the outcomes for upcoming matches and generate a formatted message for sharing, run the make_predictions.py script:
python scripts/makepredictions.py --modelsdir models --datadir data/processed --outputfile finalpredictions.txt --jsoncompetitions data/next_matches.json
This script will:
- Load the pre-trained models and the processed data.
- Make predictions for upcoming matches based on the next matches data.
- Format the predictions into a redable
.txtmessage and save it to the specified output file.
Supported Leagues
For the moment, the team name mapping has been done manually. The predictions currently support the following leagues:
- Premier League: E0
- Serie A: I1
- Ligue 1: F1
- La Liga (Primera Division): SP1
- Bundesliga: D1
Contributing
If you want to contribute to this project, please fork the repository and submit a pull request. For major changes, please open an issue first to discuss what you would like to change.
License
This project is licensed under the BSD-3-Claude license - see the LICENSE file for details.
Disclaimer
This project is intended for educational and informational purposes only. While the AIFootballPredictions system aims to provide accurate predictions for football matches, it is important to understand that predictions are inherently uncertain and should not be used as the sole basis for any decision-making, including betting or financial investments.
The predictions generated by this system can be used as an additional tool during the decision-making process. However, they should be considered alongside other factors and sources of information.
The authors of this project do not guarantee the accuracy, reliability, or completeness of any information provided. Use the predictions at your own risk, and always consider the unpredictability of sports events.
By using this software, you agree that the authors and contributors are not responsible or liable for any losses or damages of any kind incurred as a result of using the software or relying on the predictions made by the system.