danforthcenter / plantcv

Plant phenotyping with image analysis
Mozilla Public License 2.0
659 stars 264 forks source link

Naive Bayes Multiclass error : singular matrix #229

Closed sakuranbokis closed 6 years ago

sakuranbokis commented 6 years ago

Hi

I've started learning how to use PlantCV and I got stuck at Naive Bayes Multiclass classification.

I am now following the example - classifying disease area of leaves with four classes

and when I execute the code it gives me error message : LinAlgError : singular matrix

image (Tested both on Win7 and Ubuntu 16)

and if I have only two classes (like plant and background) it works well.

What should I do? Thanks for reading.

nfahlgren commented 6 years ago

Hi @sakuranbokis, the error is occurring during kernel density estimation. I can think of two potential causes. 1) In at least one class there are not enough sample points. There’s no firm number because there’s a relationship to how diverse the class colors are, but I think ~100 works as a minimum most of the time. 2) One of the classes doesn’t have enough variation. Sometimes the background class is very clean (e.g. all black or white) and the kernel density algorithm fails because the distribution of colors in the class is too uniform. Do either of these sound possible for your case?

lydiakienbaum commented 3 years ago

As @nfahlgren has explained, the class colors need to be more diverse. I could solve the issue by removing the duplicates from the script.