A monte-carlo forecaster and drafter for baseball performance
Project description
# baseballforecaster
baseballforecaster
is a Python library built on top of pybaseball for forecasting baseball performance and simulating fantasy baseball drafts. Currently, full-season monte carlo-based forecasting and drafting is available to generate risk-adjusted players to more accurately measure performance. We are developing in-season monte carlo-based forecasting, full season and in-season lookup-based forecasting, as well as full-season and in-season ML-based forecasting.
The Forecaster
module is the standard method for full-season forecasting and drafting. The user can select the time period for analysis, the number of simulations, number of draft rounds, number of drafters, and number of draft iterations. Dictionaries are constructed for each player, by each specified timestamp(date or year), by scraping data using pybaseball. Mean-shift clustering from sklearn is used to create player groups and to serve as a reference point for comparisons and developing performance distributions for each player, so we have more information for sampling. We then use monte-carlo simulations to develop full-season player performance distributions and generate risk-adjusted scores. Fantasy points totals are then calculated using standard fantasy baseball scoring.
Finally, we adapt a monte carlo search tree approach for drafting players to accurately value position importance, performance, and risk. An excel file of the results is then saved for further analysis.
We will continue to allow for greater flexbility and complexity as we develop and improve these techniques. You can further explore the source code in the src folder.
Installation
Installation is made simple by using pip:
pip install baseballforecaster
You can also simply clone the repo and run the following:
pip install -e .
Usage
Here is a simple example using Forecaster
We will use the pybaseball
library to scrape and consolidate the data and we can use tkinter
to provide a simple GUI for the user to enter the time period for analysis, the number of simulations, draft rounds, number of drafters, draft iterations, and the exploration factor. Then, just pass the Forecaster
object into the Drafter
object to use the forecasted player scores to simulate a fantasy baseball draft. All results are then conveniently stored as pandas dataframes for further analysis
Forecaster
Example :
#import the libraries
from baseballforecaster import Forecaster, Drafter, entry, get_dates
#perform the analysis:
if __name__ == "__main__":
#get parameters for forecasting
simulations, num_competitors, num_rounds, num_iterations = entry()
#get the time period for forecastings
time_period = get_dates()
#create Forecaster object
forecaster = Forecaster(simulations, num_competitors, num_rounds, num_iterations,time_period)
#perform monte carlo simulation to forecast player performance
forecaster.monte_carlo_forecast()
#define the drafter object
drafter = Drafter(forecaster)
#simulate a fantasy baseball draft
drafter.draft()
#save the forecasting, clustering, and drafting results
drafter.excel_converter()
Contributing
We are open to pull requests and look forward to expanding this library further to tackle more complex games. Please open an issue to discuss any changes or improvements.
To install baseballforecaster
, along with the tools you need to develop and run tests, run the following in your virtualenv:
$pip install -e .[dev]
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file baseballforecaster-0.0.7.tar.gz
.
File metadata
- Download URL: baseballforecaster-0.0.7.tar.gz
- Upload date:
- Size: 13.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.0 importlib_metadata/3.7.3 packaging/20.4 pkginfo/1.5.0.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc5f5b77f56ce16576e27adb603d93ff02322842bec47ee897bf5ad4a63f3902 |
|
MD5 | 0c7a6b6e120722673422465a4546254c |
|
BLAKE2b-256 | 2cf95f96e40109042707ddf027a26b09d6ba15205f07834b53b83ced8099d35e |
File details
Details for the file baseballforecaster-0.0.7-py3-none-any.whl
.
File metadata
- Download URL: baseballforecaster-0.0.7-py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.0 importlib_metadata/3.7.3 packaging/20.4 pkginfo/1.5.0.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad9773c18a2a8748d65a66ab923dd184b226e4b849a059d6b3bb5a1788386627 |
|
MD5 | 6fa7420f9f8a8ddb5e4bbf3490ce9ad8 |
|
BLAKE2b-256 | dfb048d77930b73cced810fa892a0d751c819676b3aed23fe5db8b9cc0815b33 |