Number of neurons per hidden layer

Obviously, the number of neurons in the input and output layers is determined by the type of input and output your task requires. For example, if your dataset has a shape of 28 x 28, it should expect to have input neurons of size 784, and the output neurons should be equal to the number of classes to be predicted.

We have seen in this project how it works in practice in the next example using MLP, where we set 256 neurons, four each for the hidden layers; that's just one hyperparameter to tune instead of one per layer. Just like the number of layers, you can try increasing the number of neurons gradually until the network starts overfitting.

Get Scala Machine Learning Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.