Skip to content

Instantly share code, notes, and snippets.

@toshihikoyanase
Created July 31, 2019 10:49
Show Gist options
  • Save toshihikoyanase/838e3aa03bfce7dab478c348a0e1cc6d to your computer and use it in GitHub Desktop.
Save toshihikoyanase/838e3aa03bfce7dab478c348a0e1cc6d to your computer and use it in GitHub Desktop.
Pseudo-code of Pruning
import ...
def objective(trial):
...
alpha = trial.suggest_loguniform('alpha', 1e-5, 1e-1)
clf = sklearn.linear_model.SGDClassifier(alpha=alpha)
for step in range(100):
clf.partial_fit(train_x, train_y, classes=classes)
# Report intermediate objective value.
intermediate_value = 1.0 - clf.score(test_x, test_y)
trial.report(intermediate_value, step)
# Handle pruning based on the intermediate value.
if trial.should_prune():
raise optuna.structs.TrialPruned()
return clf.score(test_x, test_y)
study = optuna.create_study(direction='maximize')
study.optimize(objective, n_trials=100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment