使用GridSearchCV拟合MLPregressor模型
我正在尝试将 GridSearchCV
与MLPRegressor一起使用,以适应我的输入和输出数据集之间的关系。 GridSearchCV.Predict()
方法是否使用交叉验证期间学到的最佳参数,还是我需要手动创建新的 mlpregessor
?
这个工作吗?
# 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)
还是我需要使用最佳参数手动创建新模型?
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
预测
GridSearchCV
对象将使用网格搜索过程中找到的最佳参数。因此,您的第一个代码块是正确的。这适用于Scikit-Learn版本1.1.1,至少回到0.16.1(我发现了最古老的版本),可以通过检查Scikit-Learn网站上的
GridSearchCV
文档来验证这一点。The
predict
method for theGridSearchCV
object will use the best parameters found during the grid search. So your first block of code is correct. This applies to scikit-learn version 1.1.1 and goes back to at least 0.16.1 (the oldest version I spot checked)This can be verified by checking the
GridSearchCV
documentation on the scikit-learn site.https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.GridSearchCV.html#sklearn.model_selection.GridSearchCV