optuna.pruners.NopPruner
- class optuna.pruners.NopPruner[source]
トライアルを決してプルーニングしないプルーナー。
使用例
import numpy as np from sklearn.datasets import load_iris from sklearn.linear_model import SGDClassifier from sklearn.model_selection import train_test_split import optuna X, y = load_iris(return_X_y=True) X_train, X_valid, y_train, y_valid = train_test_split(X, y) classes = np.unique(y) def objective(trial): alpha = trial.suggest_float("alpha", 0.0, 1.0) clf = SGDClassifier(alpha=alpha) n_train_iter = 100 for step in range(n_train_iter): clf.partial_fit(X_train, y_train, classes=classes) intermediate_value = clf.score(X_valid, y_valid) trial.report(intermediate_value, step) if trial.should_prune(): assert False, "このプルーナーでは should_prune() は常に False を返すべきです。" raise optuna.TrialPruned() return clf.score(X_valid, y_valid) study = optuna.create_study(direction="maximize", pruner=optuna.pruners.NopPruner()) study.optimize(objective, n_trials=20)
メソッド
prune
(study, trial)Judge whether the trial should be pruned based on the reported values.
- prune(study, trial)[source]
報告された値に基づいて、トライアルをプルーニングすべきかどうかを判定します。
このメソッドはライブラリの利用者が直接呼び出すことを想定していません。代わりに、
optuna.trial.Trial.report()
とoptuna.trial.Trial.should_prune()
が 目的関数内でプルーニング機構を実装するためのインターフェースを提供します。- Parameters:
study (Study) – 対象のスタディオブジェクト。
trial (FrozenTrial) – 対象のトライアルオブジェクト(凍結済み)。 このオブジェクトを変更する前にコピーを作成してください。
- Returns:
トライアルをプルーニングすべきかどうかを表すブール値。
- Return type: