I would like to do a PCA on a 9band raster image to reduce the total number of inputs bands to 3. However, I'm not able to do it as I don't think I understand what sklearn is doing in its PCA.
import skimage, rasterio, numpy, os from rasterio.plot import reshape_as_raster, reshape_as_image infile = r"C:/.../.../Sentinelimage9bands.tif" im = rasterio.open(infile) arr = im.read() pca = sklearn.decomposition.pca(n_components = 3) arrs = reshape_as_image(arr) pca.fit(arrs)
Resulting error: "Found array with dim 3. Estimator expected <= 2"
How am I supposed to do the PCA if it can't accept more than 2 dimensions? Moreover, if I flatten the array into 1 dimension, how will I know the explained variance from each band?