Note
Go to the end to download the full example code or to run this example in your browser via Binder
HPO - Random Search¶
Experiment initialization and data preparation
import scipy
from piml import Experiment
from piml.models import GLMClassifier
exp = Experiment()
exp.data_loader("SimuCredit", silent=True)
exp.data_summary(feature_exclude=["Race", "Gender"], silent=True)
exp.data_prepare(target="Approved", task_type="classification", silent=True)
Train Model
exp.model_train(model=GLMClassifier(), name="GLM")
Define hyperparameter search space for grid search
parameters = {'l1_regularization': scipy.stats.uniform(0, 0.1),
'l2_regularization': scipy.stats.uniform(0, 0.1)}
Tune hyperparameters of registered models
result = exp.model_tune("GLM", method="randomized", parameters=parameters, n_runs=100,
metric="AUC", test_ratio=0.2)
result.data
Refit model using a selected hyperparameter
params = result.get_params_ranks(rank=1)
exp.model_train(GLMClassifier(**params), name="GLM-HPO-RandSearch")
Compare the default model and HPO refitted model
exp.model_diagnose("GLM", show="accuracy_table")
ACC AUC F1 LogLoss Brier
Train 0.6722 0.7309 0.6965 0.6047 0.2088
Test 0.6690 0.7318 0.6976 0.6073 0.2095
Gap -0.0032 0.0009 0.0011 0.0026 0.0008
Compare the default model and HPO refitted model
exp.model_diagnose("GLM-HPO-RandSearch", show="accuracy_table")
ACC AUC F1 LogLoss Brier
Train 0.6721 0.7309 0.6964 0.6047 0.2088
Test 0.6690 0.7318 0.6976 0.6073 0.2095
Gap -0.0031 0.0009 0.0012 0.0026 0.0008
Total running time of the script: ( 1 minutes 24.760 seconds)
Estimated memory usage: 15 MB