I used Iris dataset for classification with 3 layer Neural Network
I decided to use :
3 neurons for input since it has 3 features,
3 neurons for output since it has 3 classes and
In the hidden layer what is the best number of neurons to do classification in this case?


2 Answers 2


And to automate the evaluations, you can use a tool like, Keras Tuner https://keras-team.github.io/keras-tuner/

From their docs, an example setup would look like this.

The min-max value for the units is where you would tune it for your case.

from tensorflow import keras
from tensorflow.keras import layers
from kerastuner.tuners import RandomSearch

def build_model(hp):
    model = keras.Sequential()
    model.add(layers.Dense(10, activation='softmax'))
                      values=[1e-2, 1e-3, 1e-4])),
    return model

There is not a clear a answer for this question. You should try and evaluated how the models performs testing diffferents configurations. But, basically, the next two premises are followed:

  • More neurons per layer --> more complex model, and probably you will obtain better accuracy.
  • More hidden layers --> more complex model, and again, probably you will obtain better accuracy.
  • WARNING Both approaches increase the chance of overfitting by increasing the complexity of model. You need to carefully evaluate them through statistically robust model selection procedures e.g. cross-validation

Be aware that incrementing the complexity of the model will increase the computational process and , as mentioned, be careful with overfitting.

I recommend try a small number of neurons first, and then, try to increase step by step seeing if some improvement is achieved in the model.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.