optuna.study.create_study

optuna.study.create_study(*, storage=None, sampler=None, pruner=None, study_name=None, direction=None, load_if_exists=False, directions=None)[源代码]

创建一个新的 Study

示例

import optuna


def objective(trial):
    x = trial.suggest_float("x", 0, 10)
    return x**2


study = optuna.create_study()
study.optimize(objective, n_trials=3)
参数:
  • storage (str | storages.BaseStorage | None) –

    数据库 URL。如果此参数设置为 None,则使用 InMemoryStorage,且 Study 将不会持久化。

    注意

    当传入数据库 URL 时,Optuna 内部使用 SQLAlchemy 来处理数据库。更多详情请参考 SQLAlchemy 的文档。如果您想为 SQLAlchemy Engine 指定非默认选项,您可以实例化一个带有所需选项的 RDBStorage 并将其作为 storage 参数传递,而不是使用 URL。

  • sampler ('samplers.BaseSampler' | None) – 实现值建议背景算法的采样器对象。如果指定 None,则在单目标优化期间使用 TPESampler,在多目标优化期间使用 NSGAIISampler。另请参阅 samplers

  • pruner (pruners.BasePruner | None) – 决定提前停止无望试行的剪枝器对象。如果指定 None,则默认使用 MedianPruner。另请参阅 pruners

  • study_name (str | None) – Study 的名称。如果此参数设置为 None,则会自动生成一个唯一的名称。

  • direction (str | StudyDirection | None) –

    优化方向。设置为 minimize 表示最小化,设置为 maximize 表示最大化。您也可以传递相应的 StudyDirection 对象。directiondirections 不能同时指定。

    注意

    如果 directiondirections 都没有指定,则 study 的方向默认设置为“minimize”。

  • load_if_exists (bool) – 控制处理 study 名称冲突的行为的标志。如果在 storage 中已经存在名为 study_name 的 study,则如果 load_if_exists 设置为 False,将引发 DuplicatedStudyError。否则,将跳过 study 的创建,并返回现有的 study。

  • directions (Sequence[str | StudyDirection] | None) – 多目标优化期间的方向序列。directiondirections 不能同时指定。

返回值:

一个 Study 对象。

返回类型:

Study

另请参阅

optuna.create_study()optuna.study.create_study() 的别名。

另请参阅

教程 使用 RDB 后端保存/恢复 Study 提供了使用 RDB 保存和恢复优化的具体示例。