How to set up params for a model?

Hello,
I wanted to set columntransformer__num-preprocessor__with_std=False for the following model:

preprocessor = ColumnTransformer([('cat-preprocessor', categorical_preprocessor, categorical_columns),
                                  ('num-preprocessor', numerical_preprocessor, numerical_columns)])
alphas = np.logspace(-2, 3, num=20)
model = make_pipeline(preprocessor, RidgeCV(alphas=alphas, store_cv_values=True))

I wrote:
model.set_params(columntransformer__num-preprocessor__with_std = False)
But got:
NameError: name 'columntransformer__num' is not defined

However, given model.get_params()['columntransformer__num-preprocessor__with_std'], I got ā€œTrueā€.

Any thoughts?

Indeed, your code is correct. However, we made a mistake while naming the preprocessors in the ColumnTransformer by using dash -.

Basically, we could use as you did the variable name columntransformer__num-preprocessor__with_std. However, having the - in the middle makes that this variable is not a proper Python variable and thus it crashes. So there are 2 possibilities to resolve the issue:

  • rename num-preprocessor to num_preprocessor
  • pass a dictionary in set_params instead of the variable name. In this case, we are dealing with string and there is not issue with the Python language. So for instance:
model.set_params(**{
    "columntransformer__num-preprocessor__with_mean": False
})

We should rename these transformers in the next sessions. I am tagging the as nice-to-have

thank you very much for quickly helping address this bug.

Jā€™ai fait une PR que jā€™ai mergĆ©e puis revertĆ©e quelques minutes plus tard. La PR changeait un CSV et je crois pas quā€™il y ait une bonne faƧon de reset un CSV comme on reset un notebook dans lā€™espace utilisateur JupyterHub ā€¦

1 Like

Fixed in FIX do not use `-` in pipeline step names by ArturoAmorQ Ā· Pull Request #480 Ā· INRIA/scikit-learn-mooc Ā· GitHub