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 aDataOpwith.skb.make_learner(),.skb.make_randomized_search(), etc.The wrapped learner can be retrieved from the
learnerattribute.- Parameters:
- learnerSkrubLearner, ParamSearch or OptunaParamSearch
The learner to wrap.
- X
strorint, default=”X” Name or ID of the node that receives the
Xargument.- y
strorintorNone, default=”y” Name or ID of the node that receives the
yargument.- environment
dictorNone, default=None Additional environment to which X and y are added before evaluation.
See also
SkrubLearner.with_sklearn_interfaceCreate 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
environmentattribute.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
environmentattribute.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 withDataOp.skb.make_learner(). When the learner is itself a skrub hyperparameter search (e.g. created withDataOp.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 caseouter_gridis returned unchanged.- Parameters:
- key_prefix
str, 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_grid
dict,listof dicts orNone, 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.
- key_prefix
- Returns:
listofdictThe parameter grid. If the wrapped learner is a hyperparameter search (
ParamSearchorOptunaParamSearch), 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']}]
- 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:
- **params
dict Estimator parameters.
- **params
- Returns:
- selfestimator instance
Estimator instance.
Gallery examples#
Turn a DataOp into a “standard” scikit-learn estimator