pythonsomspectral-python

3D data with SUSI


I am trying to use SUSI on hyperspectral data, but I am getting errors. I am sure that I am the problem and not SUSI.

import susi as su
import spectral as sp
import spectral.io.envi as envi
import numpy as np
import matplotlib.pyplot as plt
import matplotlib


box = envi.open('C:/path/ref_16-2_22/normalised.hdr')
data = np.array(box.load())
som = su.SOMClassifier(n_rows=data.shape[0], n_columns=data.shape[1])
som.fit(data)
ValueError: estimator requires y to be passed, but the target y is None
som = su.SOMClustering(n_rows=data.shape[0], n_columns=data.shape[1])
som.fit(data)
ValueError: Found array with dim 3. None expected <= 2.

I am definitely the problem! Has anyone used SUSI on 3D data?


Solution

  • In general: the dimensions of the SOM (rows and columns) don't have to relate to the dimensions of your data.

    For susi: You are using a classifier on data without class labels. in som.fit, you need to pass also the labels y:

    som.fit(data, y)
    

    data can be an n-D array, y would be a 1D array in your case I guess.

    Alternatively, you can use unsupervised clustering:

    som = SOMClustering()
    som.fit(data)
    

    [Disclaimer: I am the developer of susi.]