optuna.study.create_study¶
-
optuna.study.create_study(storage: Optional[Union[str, optuna.storages._base.BaseStorage]] = None, sampler: Optional[optuna.samplers._base.BaseSampler] = None, pruner: Optional[optuna.pruners._base.BasePruner] = None, study_name: Optional[str] = None, direction: Optional[str] = None, load_if_exists: bool = False, *, directions: Optional[Sequence[str]] = None) → optuna.study.Study[source]¶ Create a new
Study.Example
import optuna def objective(trial): x = trial.suggest_uniform("x", 0, 10) return x ** 2 study = optuna.create_study() study.optimize(objective, n_trials=3)
- Parameters
storage –
Database URL. If this argument is set to None, in-memory storage is used, and the
Studywill not be persistent.Note
When a database URL is passed, Optuna internally uses SQLAlchemy to handle the database. Please refer to SQLAlchemy’s document for further details. If you want to specify non-default options to SQLAlchemy Engine, you can instantiate
RDBStoragewith your desired options and pass it to thestorageargument instead of a URL.sampler – A sampler object that implements background algorithm for value suggestion. If
Noneis specified,TPESampleris used as the default. See alsosamplers.pruner – A pruner object that decides early stopping of unpromising trials. If
Noneis specified,MedianPruneris used as the default. See alsopruners.study_name – Study’s name. If this argument is set to None, a unique name is generated automatically.
direction –
Direction of optimization. Set
minimizefor minimization andmaximizefor maximization.Note
If none of direction and directions are specified, the direction of the study is set to “minimize”.
directions – A sequence of directions during multi-objective optimization.
load_if_exists – Flag to control the behavior to handle a conflict of study names. In the case where a study named
study_namealready exists in thestorage, aDuplicatedStudyErroris raised ifload_if_existsis set toFalse. Otherwise, the creation of the study is skipped, and the existing one is returned.
- Returns
A
Studyobject.- Raises
ValueError – If the length of
directionsis zero. Or, ifdirectionis neither ‘minimize’ nor ‘maximize’ when it is a string. Or, if the element ofdirectionsis neither minimize nor maximize. Or, if bothdirectionanddirectionsare specified.
See also
optuna.create_study()is an alias ofoptuna.study.create_study().