Created
July 31, 2019 10:49
-
-
Save toshihikoyanase/838e3aa03bfce7dab478c348a0e1cc6d to your computer and use it in GitHub Desktop.
Pseudo-code of Pruning
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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