XySkrubLearner#

class skrub.XySkrubLearner(learner, X='X', y='y', environment=None)[source]#

Wrapper to expose a standard scikit-learn interface to a skrub learner.

This class is not instantiated manually, but by calling .with_sklearn_interface() on a skrub learner. Skrub learners are created from a DataOp with .skb.make_learner(), .skb.make_randomized_search(), etc.

The wrapped learner can be retrieved from the learner attribute.

Parameters:
learnerSkrubLearner, ParamSearch or OptunaParamSearch

The learner to wrap.

Xstr or int, default=”X”

Name or ID of the node that receives the X argument.

ystr or int or None, default=”y”

Name or ID of the node that receives the y argument.

environmentdict or None, default=None

Additional environment to which X and y are added before evaluation.

See also

SkrubLearner.with_sklearn_interface

Create a XySkrubLearner. See this method for all the details.

Notes

See the user guide and this example for more information.

Methods

drop_env()

Create a new XySkrubLearner with an empty environment attribute.

get_param_grid([key_prefix, outer_grid])

Get a param grid for this learner (use with GridSearchCV, RandomizedSearchCV).

get_params([deep])

Get parameters for this estimator.

set_params(**params)

Set the parameters of this estimator.

get_named_params

set_named_params

drop_env()[source]#

Create a new XySkrubLearner with an empty environment attribute.

This drops the environment but the new object wraps the same SkrubLearner, any fitted state is retained.

get_param_grid(key_prefix='', outer_grid=None)[source]#

Get a param grid for this learner (use with GridSearchCV, RandomizedSearchCV).

Note

The recommended way to tune hyperparameters is to use the skrub DataOp methods DataOp.skb.make_randomized_search(), DataOp.skb.make_grid_search() rather than the scikit-learn meta-estimators.

This method is meant to be used when the learner is a plain SkrubLearner, i.e. it was created with DataOp.skb.make_learner(). When the learner is itself a skrub hyperparameter search (e.g. created with DataOp.skb.make_randomized_search()), it does its own internal tuning and from an external point of view it has no hyperparameters to tune, in this case outer_grid is returned unchanged.

Parameters:
key_prefixstr, default = “”

Keys in the grid are prefixed with this string. Typically this is the path to reach the learner in a metaestimator such as a pipeline, for example 'vectorizer__' if the learner is in a pipeline step named 'vectorizer'.

outer_griddict, list of dicts or None, default = None

Outer param grid for other steps in a pipeline. This function returns an augmented parameter grid in which the learner’s parameter ranges have been inserted.

Returns:
list of dict

The parameter grid. If the wrapped learner is a hyperparameter search (ParamSearch or OptunaParamSearch), it does its own tuning and adds nothing to the provided grid.

Examples

>>> import skrub
>>> from sklearn.pipeline import Pipeline
>>> from sklearn.linear_model import Ridge
>>> encoder = (
...     skrub.var("X")
...     .skb.apply(
...         skrub.StringEncoder(
...             n_components=skrub.choose_from([10, 20, 30], name="n_components")
...         )
...     )
...     .skb.make_learner()
...     .with_sklearn_interface()
... )
>>> pipe = Pipeline([("encoder", encoder), ("ridge", Ridge())])
>>> outer_grid = {"ridge__alpha": [.1, 1., 10.]}

We obtain a grid that can be passed to GridSearchCV that can be used for jointly tuning the parameters of the Ridge and skrub learner:

>>> encoder.get_param_grid("encoder__", outer_grid)
[{'ridge__alpha': [0.1, 1.0, 10.0], 'encoder__0:n_components': ['0:10', '1:20', '2:30']}]
get_params(deep=True)[source]#

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

set_params(**params)[source]#

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.