{"id":20940864,"url":"https://github.com/timhanewich/baseball-betting-nn","last_synced_at":"2025-04-11T15:34:25.786Z","repository":{"id":159856472,"uuid":"629756252","full_name":"TimHanewich/Baseball-Betting-NN","owner":"TimHanewich","description":"Training a neural net to predict betting odds for a baseball game at any stage in the game.","archived":false,"fork":false,"pushed_at":"2023-05-01T13:40:06.000Z","size":260,"stargazers_count":9,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T11:49:14.255Z","etag":null,"topics":["baseball","betting","betting-odds","neural-network","tensorflow"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TimHanewich.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-19T00:58:10.000Z","updated_at":"2024-12-30T03:47:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"21fc4473-d6a2-4991-95f1-185e96471289","html_url":"https://github.com/TimHanewich/Baseball-Betting-NN","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimHanewich%2FBaseball-Betting-NN","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimHanewich%2FBaseball-Betting-NN/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimHanewich%2FBaseball-Betting-NN/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimHanewich%2FBaseball-Betting-NN/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TimHanewich","download_url":"https://codeload.github.com/TimHanewich/Baseball-Betting-NN/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248432057,"owners_count":21102308,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["baseball","betting","betting-odds","neural-network","tensorflow"],"created_at":"2024-11-18T23:12:08.298Z","updated_at":"2025-04-11T15:34:25.757Z","avatar_url":"https://github.com/TimHanewich.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Predicting MLB Betting Lines with Neural Networks\nThis project leverages TensorFlow's Keras API to compile, train, and use a neural network to predict betting lines in a baseball game. Training data is gathered from ESPN (the *state*, or inputs) and DraftKings (the prediction, the outputs).\n\nSimply put - for any point in a theoretical game of baseball, this model predicts what the standard betting lines for the game should be, and thus, can predict a winner at any point before or during a game.\n\n![Baseball Betting Line Prediction Engine](https://i.imgur.com/okWJ3A9.png)\n\n\n## How to run the model\n1. Download and unzip one of the pre-trained models in the [download section below](#model-downloads).\n2. Replace the value of the `nn_model_path` variable in the [ui.py](./nn_model/ui.py) with the path of the folder *within* the unzipped folder.\n3. Install required dependencies:\n    1. **tensorflow**: `python -m pip install tensorflow`\n4. Run [ui.py](./nn_model/ui.py) to run the model and GUI!\n\n## Model Inputs (the State)\nThe model considers the following 16 inputs when predicting betting lines, in this order: \n- Away team record, as a percentage (i.e. 0.8 if the team is 8-2, meaning the team won 8 out of their 10 games total)\n- Home team record\n- Number of runs the away team has\n- Number of runs the home team has\n- Number of hits the away team has\n- Number of hits the home team has\n- Number of errors the away team has\n- Number of errors the home team has\n- The current inning - i.e. 1.0 for first inning, 2.0 for second, etc. And \"0.0\" would mean the game is yet to be started and the betting lines are a pre-game line.\n- Top or bottom of inning? Top = 0.0, Bottom = 1.0\n- Number of outs\n- Number of balls in the batter's count\n- Number of strikes in the batter's count\n- Is there a runner on first base? No = 0.0, Yes = 1.0\n- Is there a runner on second base? No = 0.0, Yes = 1.0\n- Is there a runner on third base? No = 0.0, Yes = 1.0\n\n## Model Outputs (the Prediction)\nThe model predicts four distinct betting lines, in the following order. You can read more about what each of these lines mean [here](https://sportsbook.draftkings.com/help/how-to-bet/baseball-betting-guide).\n- The *Run Line* - the \"point spread\" between the two teams.\n- The *Total Line* - the prediction for what the under/over would be for the combined number of runs in the game. \n- The *Away Team's Money Line*\n- The *Home Team's Money Line*\nUsing the odds above, particularly the money lines, we can use these to calculate the implied win probability for either team.\n\n## Model Downloads\n|Name|Parameters|Description|\n|-|-|-|\n|[model4](https://timhmsft.blob.core.windows.net/downloadable/model4.zip?sp=r\u0026st=2023-04-20T15:19:20Z\u0026se=2999-04-20T23:19:20Z\u0026spr=https\u0026sv=2021-12-02\u0026sr=b\u0026sig=AVQ9fkDrzJCz3p7XPqYQ%2Fr6lSL5o6btCZc2Mj22KnGM%3D)|7,469|Trained on ~5,300 examples. **Warning**, trained on data that likely contained errors.|\n|[model5](https://timhmsft.blob.core.windows.net/downloadable/model5.zip?sp=r\u0026st=2023-04-20T15:19:53Z\u0026se=2999-04-20T23:19:53Z\u0026spr=https\u0026sv=2021-12-02\u0026sr=b\u0026sig=3X277mvDT0%2Fp3mA1jC476jeH6QNH8sX7HcCnnLLRmwE%3D)|378,274|Trained on 5,473 examples. **Warning**, trained on data that likely contained errors.|\n|[model8](https://timhmsft.blob.core.windows.net/downloadable/model8-63e08460493e4273b.zip?sp=r\u0026st=2023-04-26T14:02:12Z\u0026se=2999-04-26T22:02:12Z\u0026sv=2021-12-02\u0026sr=b\u0026sig=joJHly6gHZGklmat2awm6O%2BXsRJaL%2FpNLKCRteJwYI4%3D)|378,274|Trained on 14,594 examples|\n\n## Training Data Downloads\nThese are `.jsonl` files. Each line is self-contained JSON object with both the state (game scenario) and real-world observed betting line information.\n|Number of Examples|Size|Description|\n|-|-|-|\n|[5,473](https://timhmsft.blob.core.windows.net/downloadable/db9jfwejio1h2ohfdsf.jsonl?sp=r\u0026st=2023-04-20T15:08:57Z\u0026se=2999-04-20T23:08:57Z\u0026spr=https\u0026sv=2021-12-02\u0026sr=b\u0026sig=6Z9yJ5P077Q7kxbhafJZ4v3CtmsFAqSuBF%2FrOZCzhng%3D)||**Warning**, likely contains errors.|\n|[16,515](https://timhmsft.blob.core.windows.net/downloadable/a784eb7c9f07.jsonl?sp=r\u0026st=2023-04-24T01:22:36Z\u0026se=2999-04-24T09:22:36Z\u0026sv=2021-12-02\u0026sr=b\u0026sig=cE5Pa2PbNAP34RB%2BYcAqlzT%2FwyMiFyF4nG1wgmW6%2F04%3D)|2 MB|**Warning**, likely contains errors.|\n|[14,594](https://timhmsft.blob.core.windows.net/downloadable/db-5fc15fc4238146.jsonl?sp=r\u0026st=2023-04-26T13:59:09Z\u0026se=2999-04-26T21:59:09Z\u0026sv=2021-12-02\u0026sr=b\u0026sig=8spNow9rkXzkYD7LmXoXnz24YHvlOpIEmTDeaajZejs%3D)|1.7 MB||\n|[41,037](https://timhmsft.blob.core.windows.net/downloadable/db-83f7cf.jsonl?sp=r\u0026st=2023-05-01T13:38:49Z\u0026se=2999-05-01T21:38:49Z\u0026sv=2021-12-02\u0026sr=b\u0026sig=klrDru2vCCUdpLk3rrUZuxDQUDS9yAUequjE6GEIFqc%3D)|4.8 MB||\n\n## In this Repo\nThis repo contains the following programs:\n- [A program for capturing training data from ESPN and DraftKings, written in .NET 7](./data_capture/)\n- [A python script to assemble, compile, train, and save a TensorFlow Keras neural network](./nn_model/train.py)\n- [A python program to leverage a pre-trained model to allow you to predict for various scenarios, leveraging a pre-trained model](./nn_model/ui.py)\n\n## Future Areas of Improvement\n- When a batter walks, ESPN will mark it with 4 balls in the count AND a man on second temporarily. If there are 4 balls and a man is on, count it as 0 balls.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimhanewich%2Fbaseball-betting-nn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimhanewich%2Fbaseball-betting-nn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimhanewich%2Fbaseball-betting-nn/lists"}