-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Upgraded model to use parameter grid - Now using pybaseball import to fetch up-to-date data over manual scrape and CSV data - Updated model features from 9 to 56 - Changed model training data from R/Gs to W/L%. - Updated terminal output to give more detailed responses and output - Separated all functions into modules for easier readability and organization - Created example env file to show how to set up env - More detailed doc strings in each file - Updated email design - Updated README
- Loading branch information
1 parent
df20258
commit f8961d1
Showing
52 changed files
with
1,119 additions
and
1,332 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
#API Link to get MLB odds from FanDuel, DraftKings, and Barstool in American odds format | ||
API_LINK = https://api.the-odds-api.com/v4/sports/baseball_mlb/odds/?regions=us&markets=h2h&bookmakers=fanduel,draftkings,barstool&oddsFormat=american&apiKey={API_KEY} | ||
|
||
#Get your free API key from https://the-odds-api.com/#get-access | ||
API_KEY = <YOUR_API_KEY> | ||
|
||
#Use the email that is set up and authorized through Gmail API: https://developers.google.com/gmail/api/guides | ||
BET_EMAIL = <BET_EMAIL> | ||
|
||
#Use the email you want the bet email to be sent to | ||
RECIPIENT_EMAIL = <RECIPIENT_EMAIL> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,47 @@ | ||
# MLB Betting Recommendation Emailer | ||
|
||
This machine learning model utilizes a Random Forest Regressor to generate recommended spread bets for Major League Baseball (MLB) games. The model fetches game data from The Odds API, which aggregates data from reputable sportsbooks such as Fanduel, DraftKings, and Barstool. | ||
This advanced machine learning model utilizes a Random Forest Regressor to generate betting recommendations for Major League Baseball (MLB) games. | ||
By leveraging aggregated data from reputed sportsbooks such as Fanduel, DraftKings, and Barstool via The Odds API, and combining it with the team's performance metrics from the 2023 season, | ||
the model provides insightful betting line recommendations. | ||
|
||
The model considers several key performance metrics that reflect a team's past performance in the current 2023 season such as: | ||
> R: Runs, | ||
## Features | ||
|
||
> H: Hits, | ||
> R/G: Runs per Game, | ||
> OPS: On-base Plus Slugging, | ||
and more. | ||
Data Aggregation: Fetches game data from The Odds API, which includes the latest betting lines from renowned sportsbooks. | ||
|
||
By comparing these metrics with the latest betting lines offered, the model can predict which spreads are most likely to be successful. | ||
Machine Learning Model: Utilizes a Random Forest Regressor to make predictions based on team performance metrics pulled from pybaseball. | ||
|
||
Email Notifications: Sends betting recommendations via email, using a well-formatted HTML template. | ||
|
||
Comprehensive Analysis: Considers various key performance metrics such as Runs, Hits, Runs per Game, On-base Plus Slugging, and more. | ||
|
||
Modular Structure: The codebase is organized into modules for data fetching, processing, model training, and email utilities, making it easy to understand and extend. | ||
|
||
## Example Email | ||
|
||
![Example](https://user-images.githubusercontent.com/43586291/235729092-86301d2e-3ccc-4912-9ad3-c3c22c88258b.png) | ||
|
||
## Technologies Used | ||
- Python | ||
- Pandas | ||
- NumPy | ||
- Scikit-learn | ||
- HTML | ||
- CSS | ||
- Gmail API | ||
- The Odds API | ||
Python | ||
Pandas | ||
Scikit-learn | ||
[pybaseball](https://github.com/jldbc/pybaseball) | ||
Gmail API | ||
[The Odds API](https://the-odds-api.com/) | ||
HTML & CSS | ||
|
||
## How to Use | ||
1. Create an account with [The Odds API](https://the-odds-api.com/) to get an API key. Store your API key in a `.env` file as `API_KEY = <apiKey>`. The API key is then used as an argument to the `fetch_data_from_api()` function in the script. | ||
|
||
2. Once you have your API key, you can paste this API link in your browser: | ||
`https://api.the-odds-api.com/v4/sports/baseball_mlb/odds/?regions=us&markets=spreads&bookmakers=fanduel,draftkings,barstool&oddsFormat=american&apiKey=**[INSERT YOUR API CODE HERE]**` | ||
1. API Setup: Create a free account with [The Odds API](https://the-odds-api.com/) to obtain an API key. Store this key in a .env file as API_KEY=<apiKey>. | ||
- Please see the Odds API docs for more info [here](https://the-odds-api.com/liveapi/guides/v4/) | ||
|
||
3. Obtain credentials for Gmail API. These credentials should be stored in a `credentials.json` file in the root directory of the project. Read more on setting up the Gmail API with Python [here](https://developers.google.com/gmail/api/quickstart/python) | ||
|
||
4. In your `.env` file, add a variable `BET_EMAIL` and use the email that is authorized with Gmail API. | ||
2. Gmail API Setup: Obtain credentials for the Gmail API and store them in a credentials.json file in the data directory. Then run modules/quickstart.py to generate a token.json file. | ||
- Read more on setting up the Gmail API with Python [here](https://developers.google.com/gmail/api/quickstart/python) | ||
|
||
5. Replace ```msg["To"] = "YOUR_EMAIL_HERE"``` on line 247 with the email you want to receive the recommendations to. | ||
3. Environment Variables: In your .env file, specify the email that is authorized with the Gmail API as BET_EMAIL and the recipient's email as RECIPENT_EMAIL. | ||
|
||
6. Once the above prerequisites are completed, you can run the `main()` function to fetch the betting lines, generate recommendations, and send an email with the recommendations to a specified recipient. | ||
4. Execution: Run the app.py script. This will fetch the betting lines, train the model, generate recommendations, and send an email with the betting recommendations to the specified recipient. | ||
|
||
## Contribute | ||
Everyone is welcome to contribute to this project! Feel free to add new features, fix bugs, or make improvements. Just fork the repository, make your changes, and submit a pull request. I appreciate your help! :) | ||
|
||
## Disclaimer | ||
This project is intended for educational purposes only. It should not be used as the sole basis for actual betting decisions. Betting involves risk, and you should only bet with money you can afford to lose. Always bet responsibly. | ||
This project is intended for educational purposes only. It should not be used as the sole basis for actual betting decisions. Betting involves risk, and you should only bet with money you can afford to lose. Always bet responsibly. |
Oops, something went wrong.