gpt4 book ai didi

python - 调整 MLPRegressor 超参数

转载 作者:行者123 更新时间:2023-12-05 02:08:08 33 4
gpt4 key购买 nike

我一直在尝试调整 MLP 模型的超参数来解决回归问题,但我总是收到收敛警告。

这是我的代码

def mlp_model(X, Y):

estimator=MLPRegressor()


param_grid = {'hidden_layer_sizes': [(50,50,50), (50,100,50), (100,1)],
'activation': ['relu','tanh','logistic'],
'alpha': [0.0001, 0.05],
'learning_rate': ['constant','adaptive'],
'solver': ['adam']}

gsc = GridSearchCV(
estimator,
param_grid,
cv=5, scoring='neg_mean_squared_error', verbose=0, n_jobs=-1)

grid_result = gsc.fit(X, Y)


best_params = grid_result.best_params_

best_mlp = MLPRegressor(hidden_layer_sizes = best_params["hidden_layer_sizes"],
activation =best_params["activation"],
solver=best_params["solver"],
max_iter= 5000, n_iter_no_change = 200
)

scoring = {
'abs_error': 'neg_mean_absolute_error',
'squared_error': 'neg_mean_squared_error',
'r2':'r2'}

scores = cross_validate(best_mlp, X, Y, cv=10, scoring=scoring, return_train_score=True, return_estimator = True)
return scores

我得到的警告是

ConvergenceWarning: Stochastic Optimizer: Maximum iterations (5000) reached and the optimization hasn't converged yet.% self.max_iter, ConvergenceWarning)

我的数据集中有 87 个特征和 1384 行,所有这些都是数字并且已经使用 MinMaxScaler 进行了缩放。如果您能指导我调整超参数,我将不胜感激。

最佳答案

好吧,您可以尝试三个选项,一个很明显,您将 max_iter 从 5000 增加到更高的数字,因为您的模型没有在 5000 以内收敛epochs,其次,尝试使用batch_size,因为你有 1384 个训练示例,你可以使用 16,32 或 64 的批量大小,这有助于收敛你的5000 次迭代内的模型,最后,您始终可以将 learning_rate_init 增加到稍高的值,因为看起来学习率很低,因为您的模型甚至在之后也没有收敛5000 次迭代。 希望这对您有所帮助

关于python - 调整 MLPRegressor 超参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61163759/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com