0
$\begingroup$

I want to classify a hyperspectral image (Indian Pines data set).

The input is of shape (145, 145, 200) = a HSI of 145x145 px with 200 bands.

Each one of the 145x145 pixels should be classified to one of the 15 classes, so 'y' is of shape 145x145 containing the labels for each one of the pixels.

After flattening X (shape is now 145 * 145, 200) and y (shape is now 145 * 145) I used:

X_train_flat, X_test_flat, y_train_flat, y_test_flat = train_test_split(X_flat, y_flat, range(X_flat.shape[0]), test_size = 0.8, random_state = 12)

knn = KNeighborsClassifier(n_neighbors=16)
knn.fit(X_train_flat, y_train_flat)
y_pred_flat = knn.predict(X_test_flat)

This seems to work, but it is not clear to me if KNeighborsClassifier really knows that a 'pixel' is actually an array of values corresponding to the 200 bands and that KNeighborsClassifier should map all of the 200 bands to a single value from y.

For example, the first pixel of X has 200 values (i.e. X[0][0][0], X[0][0][1],.., X[0][0][199]). Can KNeighborsClassifier determine that each value of input X[0][0] belongs to y[0][0]?

I hope I made my question clear enough.

$\endgroup$
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.