Python scikit learn MLPClassifier “hidden_layer_sizes”

你说的曾经没有我的故事 提交于 2020-12-27 08:07:33

问题


I am lost in the scikit learn 0.18 user manual (http://scikit-learn.org/dev/modules/generated/sklearn.neural_network.MLPClassifier.html#sklearn.neural_network.MLPClassifier):

   hidden_layer_sizes : tuple, length = n_layers - 2, default (100,)
   The ith element represents the number of neurons in the ith hidden layer.

If I am looking for only 1 hidden layer and 7 hidden units in my model, should I put like this? Thanks!

    hidden_layer_sizes=(7, 1)

回答1:


hidden_layer_sizes=(7,) if you want only 1 hidden layer with 7 hidden units.

length = n_layers - 2 is because you have 1 input layer and 1 output layer.




回答2:


In the docs:

hidden_layer_sizes : tuple, length = n_layers - 2, default (100,)

means : hidden_layer_sizes is a tuple of size (n_layers -2)

n_layers means no of layers we want as per architecture.

Value 2 is subtracted from n_layers because two layers (input & output ) are not part of hidden layers, so not belong to the count.

default(100,) means if no value is provided for hidden_layer_sizes then default architecture will have one input layer, one hidden layer with 100 units and one output layer.

From the docs again:

The ith element represents the number of neurons in the ith hidden layer.

means each entry in tuple belongs to corresponding hidden layer.

Example :

  1. For architecture 56:25:11:7:5:3:1 with input 56 and 1 output hidden layers will be (25:11:7:5:3). So tuple hidden_layer_sizes = (25,11,7,5,3,)

  2. For architecture 3:45:2:11:2 with input 3 and 2 output hidden layers will be (45:2:11). So tuple hidden_layer_sizes = (45,2,11,)



来源:https://stackoverflow.com/questions/35363530/python-scikit-learn-mlpclassifier-hidden-layer-sizes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!