-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc0bc79
commit 6194ac9
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
""" | ||
Optuna example that optimizes a classifier configuration using OptunaSearchCV. | ||
This example is the same as `sklearn/sklearn_optuna_search_cv_simple.py` except | ||
that you leave termination of the study up to the terminator callback. | ||
""" | ||
|
||
import optuna | ||
from optuna.terminator import TerminatorCallback | ||
|
||
from sklearn.datasets import load_iris | ||
from sklearn.svm import SVC | ||
|
||
|
||
if __name__ == "__main__": | ||
clf = SVC(gamma="auto") | ||
|
||
param_distributions = { | ||
"C": optuna.distributions.FloatDistribution(1e-10, 1e10, log=True), | ||
"degree": optuna.distributions.IntDistribution(1, 5), | ||
} | ||
terminator = TerminatorCallback() | ||
|
||
optuna_search = optuna.integration.OptunaSearchCV( | ||
clf, param_distributions, n_trials=100, timeout=600, verbose=2, callbacks=[terminator] | ||
) | ||
|
||
X, y = load_iris(return_X_y=True) | ||
optuna_search.fit(X, y) | ||
|
||
print("Best trial:") | ||
trial = optuna_search.study_.best_trial | ||
|
||
print(" Value: ", trial.value) | ||
print(" Params: ") | ||
for key, value in trial.params.items(): | ||
print(" {}: {}".format(key, value)) |