【问题标题】:Tuning MLPRegressor hyper parameters调整 MLPRegressor 超参数
【发布时间】:2020-07-24 14:06:19
【问题描述】:

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

【问题讨论】:

    标签: python machine-learning scikit-learn neural-network mlp


    【解决方案1】:

    嗯,您可以尝试三个选项,一个很明显,您将 max_iter 从 5000 增加到更高的数字,因为您的模型在 5000 个时期内没有收敛,其次,尝试使用batch_size,因为您有 1384 个训练示例,您可以使用 16,32 或 64 的批量大小,这有助于在 5000 次迭代内收敛您的模型,最后,您始终可以将learning_rate_init 增加到稍高的值,因为即使经过 5000 次迭代,您的模型也没有收敛,因此学习率似乎很低。 希望这会有所帮助

    【讨论】:

      猜你喜欢
      • 2017-05-09
      • 1970-01-01
      • 1970-01-01
      • 2017-10-26
      • 2018-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-12
      相关资源
      最近更新 更多