Hi, thank you for sharing the code. That helps alot.
I applied the code on my own hyperspectral image, the test result is very good with almost 100%. However, the model doesn't predict well on other similar images. One thing I can think of is because of PCA on the whole image, and different images will cause different PCA loadings. However, I tried train the model without PCA, i.e. put all spectral in, the test result is less than 40% accuarcy rate (haven't figured out why). Another thing that will compromise the model integrity is create image cube before train test split. That will mix training pixels and testing pixels all together. For any 25x25 image cube, it will definatly contain training and testing spectra.