# Implementation of Gaussian Mixture Model for clustering when dealing with multidimensional hyperspectral data in python

I have a python numpy array of size (800,800,4) which is my hyperspectral camera data.

When I try standard GMM methods from scikit-learn I get an error saying that the expected dimension of the data should be less than or equal to 2.

Current method:

gmm=GaussianMixture(covariance_type="full")

gmm=gmm.fit(data)

Are there any python packages or functions available to process higher dimensional data using gmm?

• Please don't cross-post. Jun 2 '17 at 21:46
• Try this implementation based on EM. Sep 14 '17 at 15:15

If I understand your type of data correctly, what you have is essentially an image with $800\times800 =640000$ pixels and each pixel has a vector of 4 values.

If this stands, I suppose you could then transform your data to a $640000\times4$ matrix, so as to conform with scikit-learn's data representation schema of inputting matrices of shape ($\#samples\times\#features$) and then you could use the GMM class implemented by the package.

And you could transform the data back if needed.

P.S.: On a second thought, I don't know if the spatial distribution of pixels plays a role on the generation of the GMM components. Maybe try it out and let us know?

Ok, after you have trained your model you can ask for it to predict the mixture model from which each pixel in your dataset has been generated.

That is if you run again: $clusters=gmm.predict(newdata)$ you will get an array with values $0-2$, denoting the cluster that each pixel belongs to. You can, then map these values in the image at hand, applying a mask of different color for each pixel in order to see if your model correctly identifies the three classes.

Here is an example of what I mean:

from scipy.misc import imread, imshow


• @YashKatariya Following the same line of thought you would need to transform your data in a $\#samples\times\#features$ matrix. If you want to find the class of each image, then you would transform it in a $1000 \times (60*60*3=10800)$ matrix (each image represented through its 10800 pixels, concatenated as features). Feb 12 '18 at 11:12