skrub.DataOp.skb.get_choices#

DataOp.skb.get_choices(named_only=False)[source]#

Get all the choices used in the DataOp.

Parameters:
named_onlybool, default = False

If True, only choices that have their name attribute set are returned. Those are the only names for which a value can be passed in the environment passed to eval().

If False, all choices are returned. For choices that have a name, that name is their key in the returned dictionary. For other choices, the key is arbitrary but stable for a same DataOp and its clones, and is the same string that is used in the parallel coordinate plots produced by ParamSearch.plot_results().

Returns:
dict

Keys are names, and values the corresponding choice object.

See also

DataOp.skb.get_vars

Similar function for getting variables created with var() and DataOps whose name was set with .skb.set_name.

DataOp.skb.describe_defaults

Get a dictionary showing the default values for choices. Only choices that actually get used in the default configuration are shown.

SkrubLearner.get_named_params

Get a dictionary mapping choice name to value in a SkrubLearner.

SkrubLearner.set_named_params

Set choice values by name on a SkrubLearner.

Examples

>>> import skrub
>>> dop = (
...     skrub.var("a")
...     + skrub.choose_int(0, 10, name="b")
...     + skrub.choose_float(0.0, 1.0)
... )
>>> dop.skb.get_choices()
{'b': choose_int(0, 10, name='b'), 'choose_float(0.0, 1.0)': choose_float(0.0, 1.0)}

With named_only we can restrict to choices that have an actual name (only choices with a name can be passed in an environment, and to SkrubLearner.set_named_params()):

>>> dop.skb.get_choices(named_only=True)
{'b': choose_int(0, 10, name='b')}

Similarly, vars can be obtained:

>>> dop.skb.get_vars()
{'a': <Var 'a'>}

All the names that can be passed in the environment are thus obtained with:

>>> list(dop.skb.get_vars(all_named_ops=True) | dop.skb.get_choices(named_only=True))
['a', 'b']