I am making an API, which will predict an outcome of any sports event using profound supervised classification and regression Machine Learning algorithms, and figure out coefficients of all possible outcomes(win, draw, lose) with an option to make a fixed amount of profit from each bet. As sport betting market turnover steadily grows at about +7-8% per year, the demand for betting platforms is rising. This API is meant to be used as the core in setting coefficients at any sports betting platform, especially web-based ones.
№2. Functional/non-functional requirements. Libraries
№4.Gathering data and the research itself
You can skip this section if you would use it on a web server
Otherwise, if you need reliability and independence from internet services, you can deploy an API on your local machine:
You need to have pip installed. If you have't, follow these instructions for your operating system.
git clone https://github.com/maxymkuz/Sports-predictor
Execute the following command from the root directory of this project:
pip install -r requirements.txt
pip install xgboost pandas numpy matplotlib flask flask-restful scikit-learn
Note that on linux you should use pip3 instead
python3 run.py
Key feature of this API is that the user is able to adjust profit, (s)he wants to make from a bets on average. Profit has to be of float type, in percent, and is placed in the last position in request url. For instance, if you want to set 5% profit, then the request should have a form of path/HomeTeam/AwayTeam/5.0
Definition
GET path/<string:hometeam>/<string:awayteam>/<float:profit>
All responses will have a form
{
"Status": "200 if Success, 404 otherwise",
"HomeTeam": "the name of the home team",
"AwayTeam": "the name of the away team",
"home_win": "the probability of the home team winning",
"away_win": "the probability of the away team winning",
"draw": "the probability of the draw"
}
Response
GET path/HomeTeam/AwayTeam/<float>
200 OK
Success
GET path/None/None/None
404 Not Found
if such teams doesn't exist in EPL, or profit is not float
Example requests
maxkuz.pythonanywhere.com/Arsenal/Liverpool/0.0
{
"AwayTeam": "Liverpool",
"HomeTeam": "Arsenal",
"home_win": 3.08,
"away_win": 3.28,
"draw": 2.7,
"status": 200
}
maxkuz.pythonanywhere.com/Arsenal/Liverpool/10.5
{
"AwayTeam": "Liverpool",
"HomeTeam": "Arsenal",
"home_win": 2.97,
"away_win": 2.79,
"draw": 2.44,
"status": 200
}
Notice that coefficients became lower, which means that the player would benefit less from a placed bet
The following code can be found in example.py
import requests
url = "http://maxkuz.pythonanywhere.com/"
away_team = "Chelsea"
home_team = "Man City"
profit = 5.0
response = requests.get(url + f"{home_team}/{away_team}/{profit}")
data = response.json()
Response:
{
"AwayTeam": "Chelsea",
"HomeTeam": "Man City",
"away_win": 10.17,
"draw": 2.77,
"home_win": 1.69,
"status": 200
}
If you want to play around with the code, which I used for the feature creating and Machine Learning modules training, I encourage you to check train_model.ipynb module.
/adt/coefficientsADT.py - main module to work with coefficients
/api/predictor.py is used to create features for future prediction
/api/__init__.py is main module, where all functions for API are processed
All .csv files can be downloaded [here.](https://datahub.io/sports-data/english -premier-league)
Each match in database has total of 62 statistical criteria, like
Date = Match Date (dd/mm/yy); FTHG = Full Time Home Team Goals; FTR = Full Time Result (H=Home Win, D=Draw, A=Away Win); HS = Home Team Shots; HF = Home Team Fouls Committed...`
Full list of abbreviations you can find here.
For now, I'm the only contributor to this project. If you have an idea on how to improve it, I highly encourage you to set up the project using abovementioned instructions, and open the pull request.
This project is licensed under the MIT License - see the LICENSE.md file for details.