Here I am trying to use 3 convolution layer neural network to classify a set of images (train data: (3249) , validation data: (487), test data: (326))

I have one class which is misclassified and I cannot understand what to do next. I have tried to reduce the value of dropout layer, but results got worst.

I know that the next solutions could be useful if I had bad classification for all classes :

  • Get more data

  • Try New model architecture, try something better.

  • Decrease number of features (you may need to do this manually)

  • Introduce regularization such as the L2 regularization

  • Make your network shallower (less layers)

  • Use less number of hidden units

What do you thing could be a good choice if I have only misclassifcation of one class? Number of total samples per class :

Black rot: 1180

Esca: 1383

healthy: 423

leaf blight: 1076

enter image description here

I had split the two datasets as follow:

x_train, _x, y_train, _y = train_test_split(x,y,test_size=0.2, stratify = y, random_state = 1)
x_valid,x_test, y_valid, y_test = train_test_split(_x,_y,test_size=0.4, stratify = _y, random_state = 1)
  • $\begingroup$ It would be good to get an idea of class distribution across the whole dataset, model architecture (and see a model variance / bias analysis [scikit-learn.org/stable/modules/generated/…) before making such a recommendation. If you could edit your post to at least include this information, that would be great. $\endgroup$
    – shepan6
    Aug 11, 2020 at 10:53
  • $\begingroup$ Your dataset is quite small. Did you use stratified splits to get your train/val/test sets? Do you have enough samples in the class which was misslcassified? $\endgroup$ Aug 11, 2020 at 11:48
  • $\begingroup$ yes I used 0.2 to test and 0.4 from testing dataset to train $\endgroup$
    – baddy
    Aug 11, 2020 at 12:23
  • $\begingroup$ I could not acces the link mentioned below $\endgroup$
    – baddy
    Aug 11, 2020 at 12:29
  • $\begingroup$ I noticed somthing that when I compile the model two times successively I got better results: it is normal? 0.959 (training), 0.952 (validation) and 0.969 (testing) $\endgroup$
    – baddy
    Aug 11, 2020 at 13:36

1 Answer 1


The main problem is that there are too many Escas in your dataset. If you look at the confusion matrix, the Esca column gets predicted (wrongly and correctly) much more that the others. This is clearly a symptom of a skewed data set.

Try augmenting your images to generate a larger 'super-dataset'. Then sample a 'sub-dataset' from that 'super-dataset', such that it has an equal distribution across all classes. Train on the 'sub-dataset'.

If you can't augment your data to have a better distribution across the 4 classes, here are some ideas:

  1. Modify the loss function to more aggressively penalize Black Rots classified as Escas.
  2. Split into two networks; the first differentiates between Leaf Blight-Healthy-Black Rot/Esca, and the second differentiates between Black Rot-Esca.
  • $\begingroup$ Means I need to modify the "categorical_crossentropy" so to resolve the class imbalance problems? $\endgroup$
    – baddy
    Aug 11, 2020 at 13:51
  • $\begingroup$ Well, you have to essentially create a custom loss function. But you can probably base it off of categorical_crossentropy $\endgroup$
    – shinvu
    Aug 11, 2020 at 15:15
  • $\begingroup$ Thank you a lot ! $\endgroup$
    – baddy
    Aug 11, 2020 at 15:17

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.