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,则使用内存存储,并且 Study 将不会持久化。 .. 注意:: 当传递数据库 URL 时,Optuna 内部使用 SQLAlchemy 来处理数据库。请参考 SQLAlchemy 的文档 以获取更多详细信息。 如果你想为 SQLAlchemy 引擎 指定非默认选项,你可以使用你想要的选项实例化 RDBStorage,并将其传递给 storage 参数,而不是 URL。 .. _SQLAlchemy: https://www.sqlalchemy.org/ .. _SQLAlchemy 的文档: https://docs.sqlalchemy.org/en/latest/core/engines.html#database-urls .. _SQLAlchemy 引擎: https://docs.sqlalchemy.org/en/latest/core/engines.html

  • sampler ('samplers.BaseSampler' | None) – A sampler object that implements background algorithm for value suggestion. If None is specified, TPESampler is used during single-objective optimization and NSGAIISampler during multi-objective optimization. See also samplers.

  • pruner (pruners.BasePruner | None) – A pruner object that decides early stopping of unpromising trials. If None is specified, MedianPruner is used as the default. See also pruners.

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

  • direction (str | StudyDirection | None) – 优化方向。设置 minimize 进行最小化,设置 maximize 进行最大化。你也可以传递相应的 StudyDirection 对象。directiondirections 不能同时指定。 .. note:

  • load_if_exists (bool) – Flag to control the behavior to handle a conflict of study names. In the case where a study named study_name already exists in the storage, a DuplicatedStudyError is raised if load_if_exists is set to False. Otherwise, the creation of the study is skipped, and the existing one is returned.

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

返回:

一个 Study 对象。

返回类型:

Study

参见

The 使用RDB后端保存/恢复学习 tutorial provides concrete examples to save and resume optimization using RDB.