skrub.Expr.skb.iter_pipelines_randomized#

Expr.skb.iter_pipelines_randomized(n_iter, *, random_state=None)[source]#

Get pipelines with different parameter combinations.

This generator yields a SkrubPipeline parametrized for each possible combination of choices.

The choice outcomes used in each pipeline can be inspected with SkrubPipeline.describe_params().

See also

Expr.skb.iter_pipelines_grid

Similar function but for exploring all the possible parameter combinations. Cannot be used when the expression contains some numeric ranges built with choose_float() or choose_int() with n_steps=None.

Expr.skb.get_grid_search

Pipeline with built-in exhaustive exploration of the parameter grid to select the best one.

Expr.skb.get_randomized_search

Pipeline with built-in randomized exploration of the parameter grid to select the best one.

Examples

>>> import numpy as np
>>> from sklearn import preprocessing
>>> import skrub
>>> scaler = skrub.choose_from(
...     [
...         preprocessing.MinMaxScaler(),
...         preprocessing.StandardScaler(),
...         preprocessing.RobustScaler(),
...         preprocessing.MaxAbsScaler(),
...     ],
...     name="scaler",
... )
>>> out = skrub.X().skb.apply(scaler)
>>> X = np.asarray([-4.0, 3.0, 10.0])[:, None]
>>> for p in out.skb.iter_pipelines_randomized(n_iter=2, random_state=0):
...     print("======================================")
...     print("params:", p.describe_params())
...     print("result:")
...     print(p.fit_transform({"X": X}))
======================================
params: {'scaler': 'RobustScaler()'}
result:
[[-1.]
 [ 0.]
 [ 1.]]
======================================
params: {'scaler': 'MaxAbsScaler()'}
result:
[[-0.4]
 [ 0.3]
 [ 1. ]]