调整 MLPRegressor 超参数
Tuning MLPRegressor hyper parameters
我一直在尝试调整 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 个时期内,其次,尝试使用 batch_size
,因为你有 1384 个训练示例,你可以使用 16,32 或 64 的批量大小,这有助于在 5000 次迭代内收敛您的模型,并且 最后 ,您始终可以将 learning_rate_init
增加到稍高的值,因为您的模型尚未收敛,因此学习率似乎很低即使经过 5000 次迭代。 希望对您有所帮助
我一直在尝试调整 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 个时期内,其次,尝试使用 batch_size
,因为你有 1384 个训练示例,你可以使用 16,32 或 64 的批量大小,这有助于在 5000 次迭代内收敛您的模型,并且 最后 ,您始终可以将 learning_rate_init
增加到稍高的值,因为您的模型尚未收敛,因此学习率似乎很低即使经过 5000 次迭代。 希望对您有所帮助