### set_params() 对转换器的参数更改无效

我尝试通过 set_params() 将一个填补器的 ‘strategy’ 更改为 “most_frequent”,但没有生效。

我做错了什么?

代码:

categorical_preprocessing = Pipeline(steps=[    ('cat_transformer',imputer),('encode',encoder)])numerical_preprocessing = Pipeline(steps=                                   [('numeric_transformer',imputer)])preprocessing = ColumnTransformer(transformers=[    ('cat',categorical_preprocessing,cat_feats),    ('num',numerical_preprocessing,num_feats)])feature_transformer = FeatureUnion(transformer_list=                                  [                                      ('pca',pca_transformer),                                      ('kbest',kbest)                                  ])params = {    'preprocess__cat__cat_transformer__strategy':'most_frequent',    'preprocess__num__numeric_transformer__strategy':'mean',}pipe = Pipeline(    steps = [('preprocess',preprocessing),             ('feature_selection',feature_transformer)    ])pipe = pipe.set_params(**params)print([pipe.get_params()[key] for key in params.keys()])

输出: ['mean', 'mean']


回答:

尝试将 params 中的第二个值更改为 "blatantly wrong",你就会发现问题所在。

你的管道中的 cat_transformernumeric_transformer 是同一个对象 imputer。设置该对象的参数 strategy 会在管道的两个位置上覆盖它。你应该定义两个独立的填补器实例。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注