GridSearchCV using Random Forest Reg Pipeline rfr = RandomForestRegressor(n_estimators=1, min_samples_leaf=7)
preprocess = make_column_transformer(
                 (StandardScaler(), ~categorical),
                 (OneHotEncoder(handle_unknown='ignore'), categorical))

param_grid = {"RandomForestRegressor__n_estimators": [1,10,20,50,75,200],
              "RandomForestRegressor__min_samples_leaf": range(1,10)}
pipe = make_pipeline(preprocess, RandomForestRegressor())

grid = GridSearchCV(pipe, param_grid, cv=5)


When I do grid.fit(X,y) I am getting following error. Why?

ValueError: Invalid parameter RandomForestRegressor for estimator Pipeline(memory=None,
         steps=[('columntransformer',
                 ColumnTransformer(n_jobs=None, remainder='drop',
                                   sparse_threshold=0.3,
                                   transformer_weights=None,
                                   transformers=[('standardscaler',
                                                  StandardScaler(copy=True,
                                                                 with_mean=True,
                                                                 with_std=True),
                                                  VendorID                 False
store_and_fwd_flag       False
RatecodeID               False
PULocationID             False
DOLocationID             False
passenger_count           True
trip_distance             True...
                 RandomForestRegressor(bootstrap=True, ccp_alpha=0.0,
                                       criterion='mse', max_depth=None,
                                       max_features='auto', max_leaf_nodes=None,
                                       max_samples=None,
                                       min_impurity_decrease=0.0,
                                       min_impurity_split=None,
                                       min_samples_leaf=1, min_samples_split=2,
                                       min_weight_fraction_leaf=0.0,
                                       n_estimators=100, n_jobs=None,
                                       oob_score=False, random_state=None,
                                       verbose=0, warm_start=False))],
         verbose=False). Check the list of available parameters with `estimator.get_params().keys()`.
The problem seems to be that your pipeline uses a fresh instance of RandomForestRegressor, so your param_grid is using nonexistent variables of the pipeline.  There are two choices (I tend to prefer the second):

Use rfr in the pipeline instead of a fresh RandomForestRegressor,  and change your parameter_grid accordingly (rfr__n_estimators).

Change param_grid to use the lowercased name randomforestregressor__n_estimators; see the docs on make_pipeline:

it ... does not permit naming the estimators. Instead, their names will be set to the lowercase of their types automatically.