神经网络MLPRegressor?

发布于 2025-02-07 00:51:13 字数 764 浏览 1 评论 0 原文

我正在培训神经网络(NN)。首先,我考虑了只有一个隐藏层的NN。其次,我试图构建一个带有两个隐藏层的NN。这两个NN层上的神经元数保持恒定为5。训练模型的其他参数如下所示:

对于1个隐藏层:

regr = MLPRegressor(hidden_layer_sizes=(5,), activation='logistic',solver='sgd',alpha=0.0001   ,learning_rate='constant', learning_rate_init=0.001   ,random_state=1).fit(X_treino, Y_treino)

对于2个隐藏层:

regr = MLPRegressor(hidden_layer_sizes=(5,5,), activation='logistic',solver='sgd',alpha=0.0001   ,learning_rate='constant', learning_rate_init=0.001   ,random_state=1).fit(X_treino, Y_treino)

但是,第二个NN的评分比第一个差得多。我不知道为什么....有人可以向我解释吗?

我正在使用的数据集是“ http:// archive 。

I am training a Neural Network (NN). First, I considered a NN with just one hidden layer. Second, I tried to construct a NN with two hidden layers. The number of neurons on the layer of these two NN was kept constant as 5. The other parameters of the training model are described as follow in the code:

for 1 hidden layer:

regr = MLPRegressor(hidden_layer_sizes=(5,), activation='logistic',solver='sgd',alpha=0.0001   ,learning_rate='constant', learning_rate_init=0.001   ,random_state=1).fit(X_treino, Y_treino)

for 2 hidden layer:

regr = MLPRegressor(hidden_layer_sizes=(5,5,), activation='logistic',solver='sgd',alpha=0.0001   ,learning_rate='constant', learning_rate_init=0.001   ,random_state=1).fit(X_treino, Y_treino)

Nevertheless, the Scoring of the second NN is much worse than the first. I don't know why.... Can anyone explain to me?

The DATASET that I am using is a avaiable on " http://archive.ics.uci.edu/ml/datasets/Airfoil+Self-Noise ", it leads to a regression problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

百变从容 2025-02-14 00:51:13

创建更大的NNS并不总是会创造出更好的结果,我能想到的是梯度下降的最佳解释。梯度下降是模型的权重(在这种情况下,层的大小和每一层中的节点的量)都会影响模型的学习能力。多种权重组合之间的交叉验证可用于估计给定问题的最佳权重,这称为高参数调节。可以使用MLPRegressor进行超参数调整:

param_grid = {
    'hidden_layer_sizes': [(150,100,50), (120,80,40), (100,50,30)],
    'max_iter': [50, 100],
    'activation': ['tanh', 'relu'],
    'solver': ['sgd', 'adam'],
    'alpha': [0.0001, 0.05],
    'learning_rate': ['constant','adaptive'],
}

grid = GridSearchCV(mlp_classifier, param_grid, n_jobs= -1, cv=5)
grid.fit(X_train, y_train)

print(grid.best_params_)

可以根据需要选择参数,并且可以在: https://scikit-learn.org/stable/modules/generated/generated/sklearn.neurn.neurn.neurn.neurn.network.mlpregressor.html ,尝试不同的组合,以获得更好的结果。

Creating bigger NNs does not always create better results, the best explanation I can think of is gradient descent. Gradient descent is how the weights of a model (in this case the size of the layers and the amount of nodes in each layer), affect the model's learning capabilities. Cross validation between multiple combinations of weights, can be used to estimate the best weights for a given problem, which is called hyperparameter tuning. hyperparameter tuning can be done with the MLPRegressor like this:

param_grid = {
    'hidden_layer_sizes': [(150,100,50), (120,80,40), (100,50,30)],
    'max_iter': [50, 100],
    'activation': ['tanh', 'relu'],
    'solver': ['sgd', 'adam'],
    'alpha': [0.0001, 0.05],
    'learning_rate': ['constant','adaptive'],
}

grid = GridSearchCV(mlp_classifier, param_grid, n_jobs= -1, cv=5)
grid.fit(X_train, y_train)

print(grid.best_params_)

the parameters can be chosen as you want and they can be seen at: https://scikit-learn.org/stable/modules/generated/sklearn.neural_network.MLPRegressor.html, try different combinations, to get better results.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文