6
           from mlxtend.regressor import StackingRegressor
           from sklearn.ensemble.forest import RandomForestRegressor as RFR
           from sklearn.ensemble import GradientBoostingRegressor as GBR
           import xgboost as xgb

            rfr = RFR(n_estimators=500, n_jobs=cc.ncpu, random_state=0)
            gbr = GBR(n_estimators=1000, random_state=0)
            xgr = xgb.XGBRegressor()
            mtr = RFR()  # meta regressor             
            regressors = [rfr, gbr, xgr]
            model = StackingRegressor(regressors=regressors, meta_regressor=mtr)
            param_grid = {
                'fs__threshold': ['median'],
                'fs__estimator__max_features': ['log2'],
                'clf__rfr__max_features': ['auto', 'log2'],
                'clf__gbr__learning_rate': [0.05, 0.02, 0.01],
                'clf__gbr__max_depth': [4, 5, 6, 7],
                'clf__gbr__max_features': ['auto', 'log2'],
                'clf__gbr__n_estimators': [500, 1000, 2000],
                'clf__xgr__learning_rate': [0.001, 0.05, 0.1, 0.2],
                'clf__xgr__max_depth': [2, 4, 6],
                'clf__xgr__min_child_weight': [1, 3, 5],
                'clf__xgr__n_estimators': [500, 1000],
                'clf__meta-mtr__n_estimators': [750, 1500]
            }

            rf_feature_imp = RFR(250, n_jobs=cc.ncpu)
            feat_selection = SelectFromModel(rf_feature_imp)

            pipeline = Pipeline([('fs', feat_selection), ('clf', model), ])
            gs = GridSearchCV(pipeline, param_grid=param_grid, verbose=1, n_jobs=-1, error_score=np.nan)

在上面的代码中,我想使用mlxtend投票回归器并使用随机森林来选择相关特征。但是,此代码不起作用,我收到错误

ValueError: Invalid parameter xgr for estimator StackingRegressor(meta_regressor=RandomForestRegressor(bootstrap=True, criterion='mse', max_depth=None,
           max_features='auto', max_leaf_nodes=None,
           min_impurity_split=1e-07, min_samples_leaf=1,
           min_samples_split=2, min_weight_fraction_leaf=0.0,
           n_estimators=10, n_jobs=1, oob_score=False, random_state=None,
           verbose=0, warm_start=False),
         regressors=[RandomForestRegressor(bootstrap=True, criterion='mse', max_depth=None,
           max_features='auto', max_leaf_nodes=None,
           min_impurity_split=1e-07, min_samples_leaf=1,
           min_samples_split=2, min_weight_fraction_leaf=0.0,
           n_estimators=500, n_jobs=5, oob_sc...eg:linear', reg_alpha=0, reg_lambda=1,
       scale_pos_weight=1, seed=0, silent=True, subsample=1)],
         verbose=0). Check the list of available parameters with `estimator.get_params().keys()`.

如何解决这个问题?

4

0 回答 0