我一直在尝试调整 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 进行了缩放。如果您能指导我调整超参数,我将不胜感激。