KNN Classifier Error

I have a problem with KNN Classifier. I form polygons for 4 classes ( deep water, coral reef, sand and mixed ), before I form them I have already create 4 vectors for each of them. I apply the data I want ( bands and vectors ) in KNN Classifier but when the result comes up, it is not right. There is only 1 class represented in the LabeledClasses and the other 3 are completly disapperred. Could you please suggest me any solution for my problem? Can I make my supervised classification on Coral Reefs without usind KNN Classifier?
Thanks in advance!

this is hard to troubleshoot without more information - can you please show a screenshot of your data and the training polygons, the KNN module as you have used it and the resulting product?

Of course! First the KNN data apply ( Note: it contains only the 2 of the 4 classes, I make it in order to test if it would accept deep water and coral reef )
Screenshot_1

next the polygons I form for deep water and coral reef
Screenshot_4

Finally the result I got, it contains only 100% coral reef and no deep water.
It is my first time in this forum, so I apologise for any mistake!

This is the final result

out of interest: Why do you only use three bands for classification?

I think one potential error source lies in the black areas in the middle which are classified as nodata

Which class was assigned (purple) to the scene? Coral reef or deep water?

Please try with all four classes at once. The NN in KNN stands for nearest neighbor, so it might be possible that all pixels are statistically closer to the deep water class than they are to the coral reef waterse. The more classes you offer, the more likely it is that pixels will land in a different class. Also the amount of training samples should be more balanced for this classifier (only 2 polygons for coral, but 6 for deep water)

There are equal polygons for each, If you take a closer look at the biggest island ( in the middle of the image ) you will detect the other polygons for coral reef. The purple scene represents Coral Reef. At the KNN window should I keep the number of training samples and the number of neighbours as they are?
I have already tried all four classes at once but the result was approximately the same ( 97,5% Coral Reef and the rest 2,5% for the other 3 classes ), but I will try it again.
Is there any other method in order to make the classification without using KNN?

now I see it, sorry.

Yes, you can also try the Random Forest Classifier, but it is not very good with limited rasters and small training polygons. Maybe also MaxLike or Minimum Distance are wort a try.

KNN will have problems if the polygons in different classes have similar “colors” or if the differences between polygons within a class are large. There should be some publications that discuss the choice of bands and geophysical variables for work on coral reefs. You might try elimating deep water pixels (e.g., using bathymetry) and focus on the other classes. It can be useful to look at the image data for your polygons, and perhaps do some preliminary exploration using a stats package (e.g., R) to compare within and between class variability. Rather than accepting the choice of bands defined for the sensor, intrinsic optical properties or other derived quantities may give better results.

1 Like