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()
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()
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
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
total-points-model-1.0.5.tar.gz
(18.9 kB
view details)
Built Distribution
File details
Details for the file total-points-model-1.0.5.tar.gz
.
File metadata
- Download URL: total-points-model-1.0.5.tar.gz
- Upload date:
- Size: 18.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 412dcec39d2b9bcda17f58b70a1eccd24abf9fd0db208170e6eb0edf56d0e01e |
|
MD5 | d10eade9392fcfb5ffd5ff34ebf989f3 |
|
BLAKE2b-256 | ec7a98ff75e10b3fd34bf271a2d6602d9b66c6b3d3cbbb71ce7f739e1e5233b7 |
File details
Details for the file total_points_model-1.0.5-py3-none-any.whl
.
File metadata
- Download URL: total_points_model-1.0.5-py3-none-any.whl
- Upload date:
- Size: 21.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ce57ceb16054a0de37553e19156b8c7cceeb1d5513639d7e8af74286af7f87b |
|
MD5 | 98d014c8428c0bdde75affd18e6dd9a5 |
|
BLAKE2b-256 | c8e41b6b310e5b07fa42cf5ca8dc9a2903a3b94ac96ded91402339ba178eba46 |