I’m using PB2 to tune Random Forest from scikit-learn. Here’s my code snippet
pbt = PB2(
time_attr="training_iteration",
#metric="mean_accuracy",
#mode="max",
perturbation_interval=20,
#resample_probability=0.25,
quantile_fraction=0.25, # copy bottom % with top %
log_config=True,
# Specifies the search space for these hyperparams
hyperparam_bounds={
"n_estimators" : [50, 200],
"min_samples_split" : [2, 6],
"min_samples_leaf" : [1, 4]})
start = time.perf_counter()
if not os.path.exists('tuning/'+var):
os.makedirs('./tuning/'+var)
output = f"tuning/{var}/RandomForestClassifier_{var}_.csv"
print('Working with '+var+' dataset...', file=open(output, "w"))
print('Working with '+var+' dataset...')
analysis = run(
RF_PB2,
name=f"RandomForestClassifier_PB2_{var}",
verbose=0,
scheduler=pbt,
reuse_actors=True,
local_dir="./tune_results",
#resources_per_trial={
## "cpu": 1,
# "gpu": 1
#},
#global_checkpoint_period=np.inf, # Do not save checkpoints based on time interval
checkpoint_freq = 20, # Save checkpoint every time the checkpoint_score_attr improves
checkpoint_at_end = True,
keep_checkpoints_num = 2, # Keep only the best checkpoint
checkpoint_score_attr = 'mean_accuracy', # Metric used to compare checkpoints
metric="mean_accuracy",
mode="max",
stop={
"training_iteration": 50,
},
num_samples=2,
fail_fast=True,
queue_trials=True,
config={ #https://www.geeksforgeeks.org/hyperparameters-of-random-forest-classifier/
"var": var,
"n_estimators" : tune.randint(50, 200),
"min_samples_split" : tune.randint(2, 6),
"min_samples_leaf" : tune.randint(1, 4),
"criterion" : tune.choice(["gini", "entropy"]),
"max_features" : tune.choice(["sqrt", "log2"]),
"class_weight" : tune.choice(["balanced", "balanced_subsample"])
})
It takes forever to start the sample and tuning process and I get these in my logs
|[2me[36m(pid=23487)e[0m 2021-03-07 14:11:42,588|INFO trainable.py:99 -- Trainable.setup took 24.839 seconds. If your trainable is slow to initialize, consider setting reuse_actors=True to reduce actor creation overheads.|
|---|---|
|e[2me[36m(pid=23482)e[0m 2021-03-07 14:11:43,058|INFO trainable.py:99 -- Trainable.setup took 25.309 seconds. If your trainable is slow to initialize, consider setting reuse_actors=True to reduce actor creation overheads.|
|2021-03-07 15:02:34,648|INFO pbt.py:481 -- [pbt]: no checkpoint for trial. Skip exploit for Trial RF_PB2_3ce57_00000|
Can someone please help me on what’s going on? I can share my whole script if it’s of any use.
Data frame shape - (1348645, 86)
Any help is appreciated!
Thanks in advance!