Search code examples
pythonpipelinerandom-forestgrid-search

Invalid parameter rf for estimator Pipeline


I am using RandomForestRegressor with GridSearchCV. I'm getting this error:

   ValueError: Invalid parameter RandomForestRegressor for estimator Pipeline

I don't understand why. This is my code:

 pipelines = {
        'rf': make_pipeline(StandardScaler(),
                            RandomForestRegressor(random_state=42)),


rf_hyperparameters = {
    'RandomForestRegressor__n_estimators': [100, 200, 300, 400, 500],
    'RandomForestRegressor__max_features': ['auto', 'sqrt', 0.33]
    }

hyperparameters = {
    'rf': rf_hyperparameters,
}

fitted_alternative_models = {}
for name, pipeline in pipelines.items():
    alt_model = GridSearchCV(pipeline, hyperparameters[name], cv=10, n_jobs=-1)
    alt_model.fit(X_train, y_train.values.ravel())

Thanks!


Solution

  • I changed:

    rf_hyperparameters = {
        'RandomForestRegressor__n_estimators': [100, 200, 300, 400, 500],
        'RandomForestRegressor__max_features': ['auto', 'sqrt', 0.33]
        }
    

    to:

    rf_hyperparameters = {
         'randomforestregressor__n_estimators': [100, 200, 300, 400, 500],
         'randomforestregressor__max_features': ['auto', 'sqrt', 0.33]
    }
    

    and it's working.