Skip to content

Lightweight API to predict betting coefficients using classification ML algorithms, the core feature in the implementation of any betting platform.

License

Notifications You must be signed in to change notification settings

maxymkuz/Sports-predictor

Repository files navigation

Sport's Predictor

Description

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.

Table of contents

Wiki pages:

№0. Goal of the project, Q&A

№1. Main theme

№2. Functional/non-functional requirements. Libraries

№3. ADT

№4.Gathering data and the research itself

№5.Conclusions

Installation and setup for local usage

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:

Hosting web application on your local machine

1. Installing pip

You need to have pip installed. If you have't, follow these instructions for your operating system.

2. Getting latest version of project from git

git clone https://github.com/maxymkuz/Sports-predictor

3. Installing prerequisites

a) from requirements.txt. E

Execute the following command from the root directory of this project:

pip install -r requirements.txt

b) Manual installation

pip install xgboost pandas numpy matplotlib flask flask-restful scikit-learn

Note that on linux you should use pip3 instead

To run, use the following command from root of the project
python3 run.py

Usage

Profit setting

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"
}

Sample request

For server requests, path=maxkuz.pythonanywhere.com/
for local usage, path=http://0.0.0.0:1300/

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
}
Now lets set profit to 10.5% (that means that all coefficients will increase by 10.5%)

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

Example code snippet for developing websites

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
}

Modules and Data explained

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.

Contributing

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.

Credits

Maxym Kuzyshyn. 2020))

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

About

Lightweight API to predict betting coefficients using classification ML algorithms, the core feature in the implementation of any betting platform.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published