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)

In the code above, I want to use the mlxtend voting regressor and also use a random forest to select relevant features. However, this code is not working and I get an error

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()`.

How to fix this?

cs95
  • 379,657
  • 97
  • 704
  • 746
user308827
  • 21,227
  • 87
  • 254
  • 417
  • 1
    I could not reproduce the problem (No error is raised) using latest versions of `mlxtend` and `xgboost`. Maybe an upgrade on both will help you. – Omid Jan 19 '17 at 15:16
  • 2
    Can confirm Omid's results, no error raised. What versions of the libraries are you using? – Ira Burton Jan 25 '17 at 20:58

0 Answers0