How to Integrate MindsDB into Supabase Database to Predict Football Scores and Stats
A step-by-step guide on integrating MindsDB with Supabase #MindsDBHackathon #MindsDB #Supabase
Table of contents
- Introduction
- What is Mindsdb?
- The dataset used to forecast match Outcomes
- Connecting the Dataset with Supabase
- Getting started with Mindsdb
- Integrating MindsDB with Supabase
- Importing Our Dataset to Supabase
- Understanding the Dataset
- Creating and Training our Prediction Model
- Checking the Status of our model
- Making Predictions to Our Model
- Conclusion
Introduction
Football has been the most-watched sport all over the world. Every matchday people come up with different opinions on which team wins, loses, or draws. Now with the help of AI, we can leverage a football match outcome based on the team's performance, and stats with the help of the MindsDB Machine Learning (ML) model.
Here is a live app to predict English Premier League scores.
What is Mindsdb?
MindsDB is an open-source tool that allows you to create predictive models using a dataset of your choice. With MindsDB, you have the ability to build, train, optimize, and deploy your Machine Learning models without the need for other platforms.
In this tutorial, we will explore how to use MindsDB to predict the football match outcome for English Premier League.
The dataset used to forecast match Outcomes
The dataset used was gotten from Kaggle and can be found here. It contains 20 years of EPL matches dataset and is presented in CSV format.
The English Premier League is the most popular domestic team in the world. It includes information about the match date, time, home and away teams, and detailed match statistics
Connecting the Dataset with Supabase
Getting started with Mindsdb
MindsDB provides all users with a free MindsDB Cloud version that they can access to generate predictions on their database. You can sign up for the free MindsDB Cloud Version by following the setup guide. Verify your email and log into your account and you are ready to go. Once done, you should be seeing a page like this :
Integrating MindsDB with Supabase
MindsDB provides us the ability to integrate with Supabase. Supabase is an open-source Postgres database that allows developers to store and sync data across multiple devices in real-time, a Firebase alternative.
Importing Our Dataset to Supabase
Head to the Supabase dashboard and create a new project if you can sign up, create a new project, follow the prompt, and enter your organization name, project name, and password.
Note: copy and save the password somewhere for later.
click on Create new project then wait for the project to finish setup
Click on the table editor icon on the left sidebar then create a new table, you can create a table called "epldata"
Click on import data via spreadsheet and import the CSV datasets you downloaded from Kaggle. We will be working with the 2021-2022 data file
Note: Before importing the dataset to Supabase, edit the dataset on Microsoft Excel or any supported software. change the A column Div to id respectively to make the id column a primary key as seen in the image below:
Click on the settings on the left sidebar then click on Database for the information needed to connect the Supabase with mindsDB
Head back to the MindsDB console and run the following SQL command. Replace Parameters data respectively with your Supabase database information above.
CREATE DATABASE supabase_datasource --- display name for the database
WITH ENGINE = 'supabase', --- name of the MindsDB handler
PARAMETERS = {
"host": "127.0.0.1", --- supabase database host
"port": 54321, --- supabase database port
"database": "test", --- supabase database name
"user": "supabase", --- supabase database user
"password": "password" --- supabase database password
};
Understanding the Dataset
Our main goal is to predict the Full Time Result (FTR) of the match. Our database consists of various fields but the important Columns are listed below :
Date = Match Date (dd/mm/yy)
HomeTeam = Home Team
AwayTeam = Away Team
FTHG = Full-Time Home Team Goals
FTAG = Full-Time Away Team Goals
FTR = Full Time Result (H=Home Win, D=Draw, A=Away Win)
HTHG = Half-Time Home Team Goals
HTAG = Half-Time Away Team Goals
HTR = Half-Time Result (H=Home Win, D=Draw, A=Away Win)
Referee = Match Referee
HS = Home Team Shots
AS = Away Team Shots
HST = Home Team Shots on Target
AST = Away Team Shots on Target
HHW = Home Team Hit Woodwork
AHW = Away Team Hit Woodwork
HC = Home Team Corners
AC = Away Team Corners
HF = Home Team Fouls Committed
AF = Away Team Fouls Committed
HO = Home Team Offsides
AO = Away Team Offsides
HY = Home Team Yellow Cards
AY = Away Team Yellow Cards
HR = Home Team Red Cards
AR = Away Team Red Cards
we can run the following query in the MindsDB Console to preview the data we will use to train our model:
SELECT *
FROM supabase_datasource.epldata
LIMIT 10;
Creating and Training our Prediction Model
we can run the following query in the MindsDB Console to train our model to predict the football match outcome
CREATE MODEL
mindsdb.predict_scores_model
FROM supabase_datasource
(SELECT * FROM epldata)
PREDICT FTR
GROUP BY FTHG, FTAG;
Here predict_scores_model is the name of our Predictor Model and FTR is the target value that we want to predict. Click on Run or press Shift+Enter to run our query. If we don't encounter any issues, we will get a Query Successfully Completed message.
Checking the Status of our model
Here we check the status of the newly created model we run the query in the MindsDB console as seen below :
SELECT *
FROM mindsdb.models
WHERE name='predict_scores_model';
Making Predictions to Our Model
Once the model's status is complete. We can now make predictions of our model using the SELECT statement to query for prediction results.
We can now query our model to predict football match outcomes by running the following query in the MindsDB console as seen below with the output :
SELECT m.HomeTeam, m.AwayTeam, m.FTHG, m.HTHG,m.FTR as winner, FTR_explain
FROM mindsdb.predict_scores_model as m
JOIN supabase_datasource.epldata as t
WHERE t.HomeTeam = "Arsenal"
AND t.AwayTeam = "Burnley";
We also query our model to predict football match outcomes in batch by running the following query in the MindsDB Console as seen below with the output :
SELECT *
FROM supabase_datasource.epldata
JOIN mindsdb.predict_scores_model as m limit 10;
Conclusion
You have successfully created a predictive model using MindsDB and Supabase. You can now use this model to make predictions on new data. You can also experiment with different predictor types and configurations to see what works best for your data.
You can also clone the GitHub repo to run the app on your local machine.
If you find this tutorial helpful let me know in the comment section and don't forget to like and share.