【问题标题】:Invalid parameter learning_rate for estimator RegressorChain(base_estimator=XGBRegressor估计器 RegressorChain 的参数 learning_rate 无效(base_estimator=XGBRegressor
【发布时间】:2021-10-22 00:49:20
【问题描述】:

我正在尝试在 RegressorChain XGBoost 模型上应用 RandomizedSearchCV,但出现错误:Invalid parameter learning_rate for estimator RegressorChain(base_estimator=XGBRegressor. 如果我评论网格字典中的所有值,它会起作用,否则它不接受任何参数。

相同的模型(XGBRegressor 和 RegressorChain)单独运行良好。 RandomizedSearchCV 不接受网格字典中的参数

# Setup the parameters grid
grid = {
        'n_estimators': [100, 500, 1000],
        'max_depth': [5, 10, 20, 30],
        'max_features': ["auto", "sqrt"],
        'eta': [0.09, 0.1, 0.2],
        'booster': ["dart", "gblinear"]
        }



clf = XGBRegressor(objective='reg:squarederror')
chain = RegressorChain(base_estimator=clf, order=[0, 1, 2, 3, 4,5])

# Setup RandomizedSearchCV
rs_clf = RandomizedSearchCV(estimator=chain,
                            param_distributions=grid, 
                            n_iter=10, # number of models to try
                            cv=5,
                            verbose=1,
                            random_state=42,
                            refit=True) 

# Fit the RandomizedSearchCV version of clf
rs_clf.fit(X_train, y_train) # 'rs' is short

【问题讨论】:

    标签: python-3.x scikit-learn hyperparameters chained xgbregressor


    【解决方案1】:

    由于XGBRegressorRegressorChainbase_estimatorXGBRegressor的参数变成嵌套的,必须用base_estimator__xxx寻址:

    grid = {
        'base_estimator__n_estimators': [100, 500, 1000],
        'base_estimator__max_depth': [5, 10, 20, 30],
        'base_estimator__max_features': ["auto", "sqrt"],
        'base_estimator__eta': [0.09, 0.1, 0.2],
        'base_estimator__booster': ["dart", "gblinear"]
    }
    

    【讨论】:

      猜你喜欢
      • 2018-06-28
      • 2021-08-13
      • 2020-02-22
      • 2020-09-11
      • 2017-06-13
      • 2020-12-18
      • 2020-05-31
      • 2020-09-25
      • 2016-12-20
      相关资源
      最近更新 更多