Package: baseballforecaster
ï»¿ï»¿# baseballforecasterbaseballforecasteris a Python library built on top ofpybaseballfor 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.TheForecastermodule 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 usingpybaseball. Mean-shift clustering fromsklearnis 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 amonte carlo search treeapproach 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 thesrcfolder.InstallationInstallation is made simple by usingpip:pipinstallbaseballforecasterYou can also simply clone the repo and run the following:pipinstall-e.UsageHere is a simple example usingForecasterWe will use thepybaseballlibrary to scrape and consolidate the data and we can usetkinterto 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 theForecasterobject into theDrafterobject to use the forecasted player scores to simulate a fantasy baseball draft. All results are then conveniently stored aspandasdataframes for further analysisForecasterExample :#import the librariesfrombaseballforecasterimportForecaster,Drafter,entry,get_dates#perform the analysis:if__name__=="__main__":#get parameters for forecastingsimulations,num_competitors,num_rounds,num_iterations=entry()#get the time period for forecastingstime_period=get_dates()#create Forecaster objectforecaster=Forecaster(simulations,num_competitors,num_rounds,num_iterations,time_period)#perform monte carlo simulation to forecast player performanceforecaster.monte_carlo_forecast()#define the drafter objectdrafter=Drafter(forecaster)#simulate a fantasy baseball draftdrafter.draft()#save the forecasting, clustering, and drafting resultsdrafter.excel_converter()ContributingWe 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 installbaseballforecaster, along with the tools you need to develop and run tests, run the following in your virtualenv:$pipinstall-e.[dev]LicenseMIT