Skip to content

Sampler

sklearn_optuna.optuna.Sampler

Bases: BaseClassWrapper

Wrapper for Optuna samplers used in hyperparameter optimization.

Parameters

Name Type Description Default
sampler type

Optuna sampler class to instantiate.

optuna.samplers.TPESampler
**params dict

Parameters to pass to the sampler constructor.

{}

See Also

sklearn_optuna.search.OptunaSearchCV : The main search class that uses samplers. sklearn_optuna.optuna.Storage : Wrapper for Optuna storage backends.

Source Code

Show/Hide source
class Sampler(BaseClassWrapper):
    """Wrapper for Optuna samplers used in hyperparameter optimization.

    Parameters
    ----------
    sampler : type, default=optuna.samplers.TPESampler
        Optuna sampler class to instantiate.

    **params : dict
        Parameters to pass to the sampler constructor.

    See Also
    --------
    sklearn_optuna.search.OptunaSearchCV : The main search class that uses samplers.
    sklearn_optuna.optuna.Storage : Wrapper for Optuna storage backends.
    """

    _estimator_name = "sampler"
    _estimator_base_class = optuna.samplers.BaseSampler
    _estimator_default_class = optuna.samplers.TPESampler

    def __init__(self, sampler: type = optuna.samplers.TPESampler, **params) -> None:
        super().__init__(sampler=sampler, **params)

Tutorials

The following example notebooks use this component:

  • How to Stop Optimization Early with Callbacks


    Stop unneeded work early by adding Optuna callbacks to your search.

    View · Open in marimo

  • How to Choose and Configure a Sampler


    Control the optimization algorithm and get reproducible results with Optuna samplers.

    View · Open in marimo

  • OptunaSearchCV Quickstart


    Run a fast hyperparameter search and read the best parameters and score.

    View · Open in marimo