StudyDataset¶
StudyDataset loads and saves data from/to an Optuna study.
kedro_datasets_experimental.optuna.StudyDataset ¶
StudyDataset(
*,
backend,
database,
study_name,
load_args=None,
version=None,
credentials=None,
metadata=None
)
Bases: AbstractVersionedDataset[Study, Study]
StudyDataset loads/saves data from/to an optuna Study.
Examples:
Using the YAML API:
review_prediction_study:
type: kedro_datasets_experimental.optuna.StudyDataset
backend: sqlite
database: data/05_model_input/review_prediction_study.db
load_args:
sampler:
class: TPESampler
n_startup_trials: 10
n_ei_candidates: 5
pruner:
class: NopPruner
versioned: true
price_prediction_study:
type: kedro_datasets_experimental.optuna.StudyDataset
backend: postgresql
database: optuna_db
credentials: dev_optuna_postgresql
Using the Python API:
>>> from kedro_datasets_experimental.optuna import StudyDataset
>>> from optuna.distributions import FloatDistribution
>>> import optuna
>>>
>>> study = optuna.create_study()
>>> trial = optuna.trial.create_trial(
... params={"x": 2.0},
... distributions={"x": FloatDistribution(0, 10)},
... value=4.0,
... )
>>> study.add_trial(trial)
>>>
>>> dataset = StudyDataset(backend="sqlite", database="optuna.db")
>>> dataset.save(study)
>>> reloaded = dataset.load()
>>> assert len(reloaded.trials) == 1
>>> assert reloaded.trials[0].params["x"] == 2.0
Parameters:
-
backend(str) –Name of the database backend. This name should correspond to a module in
SQLAlchemy. -
database(str) –Name of the database.
-
study_name(str) –Name of the optuna Study.
-
load_args(dict[str, Any] | None, default:None) –Optuna options for loading studies. Accepts a
samplerand apruner. If either are provided, aclassmatching any Optunasampler, respecitivelyprunerclass name should be provided, optionally with their argyments. Here you can find all available samplers and pruners and their arguments: - https://optuna.readthedocs.io/en/stable/reference/samplers/index.html - https://optuna.readthedocs.io/en/stable/reference/pruners.html All defaults are preserved. -
version(Version, default:None) –If specified, should be an instance of
kedro.io.core.Version. If itsloadattribute is None, the latest version will be loaded. If itssaveattribute is None, save version will be autogenerated. -
credentials(dict[str, Any] | None, default:None) –Credentials required to get access to the underlying RDB. They can include
username,password,host, andport. -
metadata(dict[str, Any] | None, default:None) –Any arbitrary metadata. This is ignored by Kedro, but may be consumed by users or external plugins.
Source code in kedro_datasets_experimental/optuna/study_dataset.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
DEFAULT_LOAD_ARGS
class-attribute
instance-attribute
¶
DEFAULT_LOAD_ARGS = {'sampler': None, 'pruner': None}
load ¶
load()
Source code in kedro_datasets_experimental/optuna/study_dataset.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
resolve_load_version ¶
resolve_load_version()
Compute the version the dataset should be loaded with.
Source code in kedro_datasets_experimental/optuna/study_dataset.py
184 185 186 187 188 189 190 | |
save ¶
save(study)
Source code in kedro_datasets_experimental/optuna/study_dataset.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | |