hpt
A minimal hyperparameter tuning framework to help you train hundreds of models.
It's essentially a set of helpful wrappers over optuna.
Consult the package documentation here!
Install
Install package from PyPI:
pip install hyperparameter-tuning
Getting started
from hpt.tuner import ObjectiveFunction, OptunaTuner
obj_func = ObjectiveFunction(
X_train, y_train, X_test, y_test,
hyperparameter_space=HYPERPARAM_SPACE_PATH,
eval_metric="accuracy",
s_train=s_train,
s_val=s_test,
threshold=0.50,
)
tuner = OptunaTuner(
objective_function=obj_func,
direction="maximize",
)
tuner.optimize(n_trials=20, n_jobs=4)
tuner.results
clf = obj_func.reconstruct_model(obj_func.best_trial)
Defining a hyperparameter space
The hyperparameter space is provided either path to a YAML file, or as a dict
with the same structure.
Example hyperparameter spaces here.
The YAML file must follow this structure:
DT:
classpath: sklearn.tree.DecisionTreeClassifier
kwargs:
max_depth:
type: int
range: [ 10, 100 ]
log: True
criterion:
- 'gini'
- 'entropy'
min_samples_split: 4
LR:
classpath: sklearn.linear_model.LogisticRegression
kwargs:
C:
type: float
range: [ 0.01, 1.0 ]
log: True