Fitting a MLPRegressor model using GridSearchCV

Viewed 339

I'm trying to use GridSearchCV with an MLPRegressor to fit a relationship between my input and output datasets. Does the GridSearchCV.predict() method use the best parameters learned during cross validation or do I need to manually create a new MLPRegessor?

Does this work?

# Fitting a Regression model to the train data
MLP_gridCV = GridSearchCV(
    estimator=MLPRegressor(max_iter=10000, n_iter_no_change=30),
    param_grid=param_list,
    n_jobs=-1,
    cv=5,
    verbose=5,
)
MLP_gridCV.fit(X_train, Y_train)

# Prediction
Y_prediction = MLP_gridCV.predict(X)

Or do I need to manually create a new model using the best parameters?

best_params = MLP_gridCV.best_params_
best_mlp = MLPRegressor(
    hidden_layer_sizes=best_params["hidden_layer_sizes"],
    activation=best_params["activation"],
    solver=best_params["solver"],
    max_iter=10000,
    n_iter_no_change=30,
)
best_mlp.fit(X_train, Y_train)
best_mlp.predict(X)
1 Answers
Related