Skip to main content

Train an AFL Total Points model

Project description

Total Points Model

total-points-model is a Python library with useful functions and notebooks for tuning, training and evaluating an XGBoost model.

The target of this model is the Total Points Scored in an AFL match.

Installation

Use the package manager pip to install total-points-model.

pip install total-points-model

Usage

See notebooks folder for more comprehensive examples of usage.

Data Processing

from total_points_model.domain.preprocessing.data_preprocessor import DataPreprocessor
from total_points_model.domain.contracts.mappings import Mappings
from total_points_model.domain.contracts.rolling_columns import RollingColumns

preprocessor = DataPreprocessor(Mappings=Mappings, rolling_dict=RollingColumns.rolling_dict)

preprocessor.fit(training_data)

training_data_preproc = preprocessor.transform(training_data)
test_data_preproc = preprocessor.transform(test_data)

Hyperparameter Tuning

from total_points_model.domain.modelling.hyperparameter_tuning import XGBYearHyperparameterTuner
from total_points_model.domain.modelling.optuna_xgb_param_grid import OptunaXGBParamGrid

xgb_tuner = XGBYearHyperparameterTuner(X_train_preproc, y_train, optuna_grid=OptunaXGBParamGrid, monotonicity_constraints={})
xgb_tuner.tune_hyperparameters()
params = xgb_tuner.get_best_params()

Model Building

from total_points_model.domain.modelling.supermodel import SuperXGBRegressor


super_xgb = SuperXGBRegressor(X_train = X_train_preproc, 
                              y_train = y_train, 
                              X_test = X_test_preproc, 
                              y_test = y_test, 
                              params = params)

super_xgb.fit()

train_preds = super_xgb.predict(X_train_preproc.drop(columns=["Match_ID"]))
test_preds = super_xgb.predict(X_test_preproc.drop(columns=["Match_ID"]))

Model Evaluation

from total_points_model.domain.modelling.model_evaluation import XGBRegressorEvaluator
from total_points_model.domain.contracts.modelling_data_contract import ModellingDataContract

train_xgb_evals = XGBRegressorEvaluator(model = xgb_model,
                                       data = train_evaluation_data,
                                       actual_name = ModellingDataContract.RESPONSE,
                                       expected_name = "xgb_preds",
                                       compare_name='old_preds'
                                       )
train_xgb_evals.plot_distribution()

train-dist

test_xgb_evals = XGBRegressorEvaluator(model = xgb_model,
                                       data = test_evaluation_data,
                                       actual_name = ModellingDataContract.RESPONSE,
                                       expected_name = "xgb_preds",
                                       compare_name = "old_preds"
                                       )
test_xgb_evals.plot_distribution()

test-dist

Credits

Data sourced using a private R package. Credits to dgt23.

CONTRIBUTING

I am no longer updating this package as I am exploring other AFL related analysis and packages.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

total-points-model-1.0.5.tar.gz (18.9 kB view hashes)

Uploaded Source

Built Distribution

total_points_model-1.0.5-py3-none-any.whl (21.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page