choose_from#

skrub.choose_from(outcomes, *, name=None)[source]#

A choice among several possible outcomes.

When a pipeline is used without hyperparameter tuning, the outcome of this choice is the first value in the outcomes list or dict.

Parameters:
outcomeslist or dict

The possible outcomes to choose from. If a dict, the values are the outcomes and the keys give them human-readable names used to display hyperparameter search grids and results.

namestr, optional (default=None)

If not None, name is used when displaying search results and can also be used to override the choice’s value by setting it in the environment containing a pipeline’s inputs.

Returns:
Choice

An object representing this choice, which can be used in a skrub pipeline.

See also

choose_bool

Construct a choice between False and True.

choose_float

Construct a choice of floating-point numbers from a numeric range.

choose_int

Construct a choice of integers from a numeric range.

Examples

Outcomes can be provided in a list:

>>> from skrub import choose_from
>>> choose_from([1, 2], name='the number')
choose_from([1, 2], name='the number')

They can also be provided in a dictionary to give a name to each outcome:

>>> choose_from({'one': 1, 'two': 2}, name='the number')
choose_from({'one': 1, 'two': 2}, name='the number')

When a pipeline containing a choose_from is used without hyperparameter tuning, the default outcome for the choice is used. It is the first outcome in the provided list or dict:

>>> choose_from([1, 2, 3]).default()
1