I am trying to tune an extra tree classifier with Optuna.
I am getting this message to all my trials:
[W 2022-02-10 12:13:12,501] Trial 2 failed, because the value None could not be cast to float.
Below is my code. It happens to all my trials. Can anyone tell me what I am doing wrong?
def objective(trial, X, y):
param = {
'verbose': trial.suggest_categorical('verbosity', [1]),
'random_state': trial.suggest_categorical('random_state', [RS]),
'n_estimators': trial.suggest_int('n_estimators', 100, 150),
'n_jobs': trial.suggest_categorical('n_jobs', [-1]),
}
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, shuffle=True, random_state=RS)
clf = ExtraTreesClassifier(**param)
clf.fit(X_train, y_train)
y_pred = clf.predict(X_test)
acc = accuracy_score(y_pred, y_test)
print(f"Model Accuracy: {round(acc, 6)}")
print(f"Model Parameters: {param}")
print('='*50)
return`
study = optuna.create_study(
direction='maximize',
sampler=optuna.samplers.TPESampler(),
pruner=optuna.pruners.HyperbandPruner(),
study_name='ExtraTrees-Hyperparameter-Tuning')
func = lambda trial: objective(trial, X, y)
%%time
study.optimize(
func,
n_trials=100,
timeout=60,
gc_after_trial=True
)