问题描述
假设我正在使用以下代码创建一个神经网络:
Lets say I'm creating a neural net using the following code:
from sklearn.neural_network import MLPRegressor
model = MLPRegressor(
hidden_layer_sizes=(100,),
activation='identity'
)
model.fit(X_train, y_train)
对于hidden_layer_sizes
,我只是将其设置为默认值.但是,我真的不明白它是如何工作的.我的定义中隐藏层的数量是多少?是 100 吗?
For the hidden_layer_sizes
, I simply set it to the default. However, I don't really understand how it works. What is the number of hidden layers in my definition? Is it 100?
推荐答案
来自 文档:
hidden_layer_sizes : 元组,长度 = n_layers - 2,默认 (100,)
第 i 个元素表示第 i 个隐藏层的神经元数量.
The ith element represents the number of neurons in the ith hidden layer.
它是length = n_layers - 2
,因为你的隐藏层数是n_layers
的总层数减去输入层的1,你的输入层减去1输出层.
It is length = n_layers - 2
, because the number of your hidden layers is the total number of layers n_layers
minus 1 for your input layer, minus 1 for your output layer.
在 (100,)
的(默认)情况下,它意味着一个 100 个单元(神经元)的隐藏层.
In your (default) case of (100,)
, it means one hidden layer of 100 units (neurons).
对于分别有 100、50 和 25 个单位的 3 个隐藏层,将是
For 3 hidden layers of, say, 100, 50, and 25 units respectively, it would be
hidden_layer_sizes = (100, 50, 25)
参见文档中的示例(它适用于MLPClassifier
,但逻辑是一样的).
See the example in the docs (it is for MLPClassifier
, but the logic is identical).
这篇关于SciKitLearn 中 MLPRegressor 的隐藏层大小是如何确定的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!