How is the hidden layer size determined for MLPRegressor in SciKitLearn?

前端 未结 1 862
梦毁少年i
梦毁少年i 2021-01-27 12:50

Lets say I\'m creating a neural net using the following code:

from sklearn.neural_network import MLPRegressor

model = MLPRegressor(
  hidden_layer_sizes=(100,),         


        
1条回答
  •  梦毁少年i
    2021-01-27 13:18

    From the docs:

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

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

    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.

    In your (default) case of (100,), it means one hidden layer of 100 units (neurons).

    For 3 hidden layers of, say, 100, 50, and 25 units respectively, it would be

    hidden_layer_sizes = (100, 50, 25)
    

    See the example in the docs (it is for MLPClassifier, but the logic is identical).

    0 讨论(0)
提交回复
热议问题