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 名称冲突的标志。如果 study_namestorage 中已存在,并且 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 保存和恢复优化的具体示例。