diff --git a/doc/source/_static/validation_plot.png b/doc/source/_static/validation_plot.png index 174d2a9..9fedccb 100644 Binary files a/doc/source/_static/validation_plot.png and b/doc/source/_static/validation_plot.png differ diff --git a/doc/source/dev.rst b/doc/source/dev.rst index 2ff953b..780b0f0 100644 --- a/doc/source/dev.rst +++ b/doc/source/dev.rst @@ -4,8 +4,7 @@ For Developers This section of the documentation covers things that will be useful for those already contributing to NFLWin. .. note:: - Unless stated otherwise assume that all filepaths given in this section start at the root directory for the repo. - + Unless stated otherwise assume that all filepaths given in this section start at the root directory for the repo. Testing Documentation ------------------------------------------ @@ -24,7 +23,13 @@ NFLWin comes with a pre-trained model, but if the code generating that model is $ python make_default_model.py .. note:: - This script hardcodes in the seasons to use for training and testing samples. After each season those will likely need to be updated to use the most up-to-date data. + This script hardcodes in the seasons to use for training and + testing samples. After each season those will likely need to be + updated to use the most up-to-date data. + +.. note:: + This script requires ``matplotlib`` in order to run, as it produces a + validation plot for the documentation. Cutting a New Release ---------------------------------- diff --git a/doc/source/index.rst b/doc/source/index.rst index d99eb22..14a101c 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -76,6 +76,11 @@ Once data is loaded, using the model to predict WP is easy: >>> standard_model.predict_wp(plays) array([ 0.58300397, 0.64321796, 0.18195466]) +Current Default Model +--------------------- + +.. image:: _static/validation_plot.png + Why NFLWin? -------------- Put simply, there are no other options: while WP models have been @@ -101,6 +106,3 @@ Resources Developer Documentation Full API Documentation -* :ref:`Full API Documentation ` -* :ref:`Search NFLWin's Documentation ` - diff --git a/doc/source/model.rst b/doc/source/model.rst index 39df1e5..3ed82ba 100644 --- a/doc/source/model.rst +++ b/doc/source/model.rst @@ -177,9 +177,8 @@ correctly. The ratio of these two KDEs is the actual WP measured from the test data set at a given *predicted* WP. While all of this is measured in :meth:`~nflwin.model.WPModel.validate_model`, you can plot it for yourself by calling the -:meth:`~nflwin.model.WPModel.plot_validation` method: - -.. image:: _static/validation_plot.png +:meth:`~nflwin.model.WPModel.plot_validation` method, which will +generate a plot like that shown on the home page. From there NFLWin computes both the maximum deviation at any given percentage and the total area between the estimated WP from the model diff --git a/make_default_model.py b/make_default_model.py index 6e3be3c..99ba307 100644 --- a/make_default_model.py +++ b/make_default_model.py @@ -1,24 +1,49 @@ """A simple script to create, train, validate, and save the default model""" from __future__ import division, print_function +import datetime as dt import time +import os from nflwin import model def main(): start = time.time() win_probability_model = model.WPModel() - win_probability_model.train_model(training_seasons=[2009, 2010, 2011, 2012, 2013, 2014]) + + training_seasons = [2009, 2010, 2011, 2012, 2013, 2014] + validation_seasons = [2015] + season_types = ["Regular", "Postseason"] + + win_probability_model.train_model(training_seasons=training_seasons, + training_season_types=season_types) print("Took {0:.2f}s to build model".format(time.time() - start)) start = time.time() - max_deviation, residual_area = win_probability_model.validate_model(validation_seasons=[2015]) + max_deviation, residual_area = win_probability_model.validate_model(validation_seasons=validation_seasons, + validation_season_types=season_types) print("Took {0:.2f}s to validate model, with a max residual of {1:.2f} and a residual area of {2:.2f}" .format(time.time() - start, max_deviation, residual_area)) win_probability_model.save_model() + ax = win_probability_model.plot_validation(label="max deviation={0:.2f}, \n" + "residual total area={1:.2f}" + "".format(max_deviation, residual_area)) + curr_datetime = dt.datetime.now() + ax.set_title("Model Generated At: " + curr_datetime.strftime("%Y-%m-%d %H:%M:%S")) + ax.legend(loc="lower right", fontsize=10) + ax.text(0.02, 0.98, ("Data from: {0:s}\n" + "Training season(s): {1:s}\n" + "Validation season(s): {2:s}" + "".format(", ".join(season_types), + ", ".join(str(year) for year in training_seasons), + ", ".join(str(year) for year in validation_seasons))), + ha="left", va="top", fontsize=10, transform=ax.transAxes) + this_filepath = os.path.dirname(os.path.abspath(__file__)) + save_filepath = os.path.join(this_filepath, "doc", "source", "_static", "validation_plot.png") + ax.figure.savefig(save_filepath) if __name__ == "__main__": diff --git a/nflwin/model.py b/nflwin/model.py index 4abea17..4efcf0e 100644 --- a/nflwin/model.py +++ b/nflwin/model.py @@ -357,7 +357,7 @@ def plot_validation(self, axis=None, **kwargs): import matplotlib.pyplot as plt if axis is None: axis = plt.figure().add_subplot(111) - axis.plot([0, 1], [0, 1], ls="--", lw=2, color="black") + axis.plot([0, 100], [0, 100], ls="--", lw=2, color="black") axis.set_xlabel("Predicted WP") axis.set_ylabel("Actual WP") axis.plot(self.sample_probabilities,