Skip to content

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.

License

Notifications You must be signed in to change notification settings

kmuffato/AI-AIFootballPredictions

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

66 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AIFootballPredictions

AIFootballPredictions is a machine learning-based system designed to predict whether a football match will have over 2.5 goals. Leveraging historical data from top European leagues (Serie A, EPL, Bundesliga, La Liga, Ligue 1), it utilizes advanced feature engineering and model training techniques to deliver accurate predictions, making it a valuable tool for sports analytics enthusiasts.

Predictions of the week

🎯 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: 2024-10-04

Premier League:

  • ⚽ Crystal Palace πŸ†š Liverpool: Over 2.5 Goals! πŸ”₯ (57.64% chance)
  • ⚽ Arsenal πŸ†š Southampton: Over 2.5 Goals! πŸ”₯ (82.33% chance)
  • ⚽ Brentford πŸ†š Wolves: Over 2.5 Goals! πŸ”₯ (51.9% chance)
  • ⚽ Leicester πŸ†š Bournemouth: Over 2.5 Goals! πŸ”₯ (90.72% chance)
  • ⚽ Man City πŸ†š Fulham: Over 2.5 Goals! πŸ”₯ (67.08% chance)
  • ⚽ West Ham πŸ†š Ipswich: Over 2.5 Goals! πŸ”₯ (60.52% chance)
  • ⚽ Everton πŸ†š Newcastle: Under 2.5 Goals (76.06% chance)
  • ⚽ Aston Villa πŸ†š Man United: Over 2.5 Goals! πŸ”₯ (64.2% chance)
  • ⚽ Chelsea πŸ†š Nott'm Forest: Under 2.5 Goals (85.56% chance)
  • ⚽ Brighton πŸ†š Tottenham: Over 2.5 Goals! πŸ”₯ (51.9% chance)

Serie A:

  • ⚽ Napoli πŸ†š Como: Over 2.5 Goals! πŸ”₯ (80.44% chance)
  • ⚽ Verona πŸ†š Venezia: Over 2.5 Goals! πŸ”₯ (73.87% chance)
  • ⚽ Udinese πŸ†š Lecce: Under 2.5 Goals (83.62% chance)
  • ⚽ Atalanta πŸ†š Genoa: Under 2.5 Goals (86.18% chance)
  • ⚽ Inter πŸ†š Torino: Over 2.5 Goals! πŸ”₯ (91.0% chance)
  • ⚽ Juventus πŸ†š Cagliari: Under 2.5 Goals (65.56% chance)
  • ⚽ Bologna πŸ†š Parma: Over 2.5 Goals! πŸ”₯ (89.08% chance)
  • ⚽ Lazio πŸ†š Empoli: Under 2.5 Goals (86.03% chance)
  • ⚽ Monza πŸ†š Roma: Under 2.5 Goals (79.91% chance)
  • ⚽ Fiorentina πŸ†š Milan: Over 2.5 Goals! πŸ”₯ (63.0% chance)

Bundesliga:

  • ⚽ Augsburg πŸ†š M'gladbach: Over 2.5 Goals! πŸ”₯ (64.12% chance)
  • ⚽ Leverkusen πŸ†š Holstein Kiel: Over 2.5 Goals! πŸ”₯ (98.81% chance)
  • ⚽ Werder Bremen πŸ†š Freiburg: Over 2.5 Goals! πŸ”₯ (61.81% chance)
  • ⚽ Union Berlin πŸ†š Dortmund: Over 2.5 Goals! πŸ”₯ (50.95% chance)
  • ⚽ Bochum πŸ†š Wolfsburg: Under 2.5 Goals (87.88% chance)
  • ⚽ St Pauli πŸ†š Mainz: Under 2.5 Goals (72.43% chance)
  • ⚽ Heidenheim πŸ†š RB Leipzig: Over 2.5 Goals! πŸ”₯ (59.4% chance)
  • ⚽ Ein Frankfurt πŸ†š Bayern Munich: Over 2.5 Goals! πŸ”₯ (77.41% chance)
  • ⚽ Stuttgart πŸ†š Hoffenheim: Over 2.5 Goals! πŸ”₯ (82.85% chance)

La Liga:

  • ⚽ Leganes πŸ†š Valencia: Over 2.5 Goals! πŸ”₯ (63.07% chance)
  • ⚽ Espanol πŸ†š Mallorca: Under 2.5 Goals (68.72% chance)
  • ⚽ Getafe πŸ†š Osasuna: Under 2.5 Goals (94.63% chance)
  • ⚽ Valladolid πŸ†š Vallecano: Under 2.5 Goals (68.59% chance)
  • ⚽ Las Palmas πŸ†š Celta: Under 2.5 Goals (67.8% chance)
  • ⚽ Real Madrid πŸ†š Villarreal: Over 2.5 Goals! πŸ”₯ (79.17% chance)
  • ⚽ Girona πŸ†š Ath Bilbao: Over 2.5 Goals! πŸ”₯ (91.36% chance)
  • ⚽ Alaves πŸ†š Barcelona: Over 2.5 Goals! πŸ”₯ (51.68% chance)
  • ⚽ Sevilla πŸ†š Betis: Over 2.5 Goals! πŸ”₯ (67.28% chance)
  • ⚽ Sociedad πŸ†š Ath Madrid: Under 2.5 Goals (59.6% chance)

Ligue 1:

  • ⚽ Marseille πŸ†š Angers: Over 2.5 Goals! πŸ”₯ (90.5% chance)
  • ⚽ St Etienne πŸ†š Auxerre: Under 2.5 Goals (56.77% chance)
  • ⚽ Lille πŸ†š Toulouse: Over 2.5 Goals! πŸ”₯ (65.51% chance)
  • ⚽ Rennes πŸ†š Monaco: Over 2.5 Goals! πŸ”₯ (84.85% chance)
  • ⚽ Lyon πŸ†š Nantes: Over 2.5 Goals! πŸ”₯ (63.52% chance)
  • ⚽ Brest πŸ†š Le Havre: Over 2.5 Goals! πŸ”₯ (73.1% chance)
  • ⚽ Strasbourg πŸ†š Lens: Under 2.5 Goals (79.27% chance)
  • ⚽ Reims πŸ†š Montpellier: Over 2.5 Goals! πŸ”₯ (91.67% chance)
  • ⚽ Nice πŸ†š Paris SG: Over 2.5 Goals! πŸ”₯ (72.06% chance)

Table of Contents

  1. Project Overview
  2. Directory Structure
  3. Setup and Installation
  4. Data Acquisition
  5. Data Preprocessing
  6. Model Training
  7. Upcoming Matches Acquisition
  8. Making Predictions
  9. Supported Leagues
  10. Contributing
  11. License
  12. Support
  13. 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:

  1. Data Acquisition: Download and merge historical football match data from multiple European leagues.
  2. Data Preprocessing: Process the raw data to engineer features, handle missing values, and select the most relevant features.
  3. Model Training: Train several machine learning models, perform hyperparameter tuning, and combine the best models into a voting classifier to make predictions.
  4. 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:

  1. Clone the repository:

    git clone https://github.com/yourusername/AIFootballPredictions.git
    cd AIFootballPredictions
  2. 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.
  • 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:

  1. Register for an API Key:

  2. Create a ~/.env File:

    • This file will be used by the load_dotenv library to set up the API_FOOTBALL_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.
  3. Insert the API Key:

    • After running the vim command, press the i key (for "insert mode").
    • Write down the following line, replacing your_personal_key with your actual API key:
      • API_FOOTBALL_DATA=your_personal_key
  4. Save and Exit:

    • Press the Esc key to exit insert mode.
    • Then, type :wq! and press Enter to save the changes and exit the editor.
  5. 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_DATA 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/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 models and the processed data.
  • Make predictions for upcoming matches based on the next matches data.
  • Format the predictions into a redable .txt message 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

For this reason be carful when executing the data acquisition step.

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.

Support

If you find this project helpful and would like to support its development, you can buy me a coffee! Your support is greatly appreciated! β˜•οΈπŸ˜Š

Buy Me A Coffee

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.

About

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.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Jupyter Notebook 95.3%
  • Python 4.7%