Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

K-Nearest Neigbors (knn) Classifier

Data

  1. We load training areas from data/training_areas_ml.geojson.

  2. Spectral band values (Green, Red, NIR) are simulated from class-specific reflectance profiles.

  3. The binary target is already encoded: ml_label = 1 (Corn/Maize) vs ml_label = 0 (Non-Corn).

  4. We normalize the features to [0, 1] and split into training and testing sets.

Decision Boundaries

Next, we are going to define a function to plot the decision boundary.

KNN Classification Procedure

We are going to initialize and train a KNN classifier. We create an instance of the KNN model, setting the number of neighbors (n_neighbors) to 3 and 5.

👩🏽‍💻 TEST IT OUT

How about if we want to check for 5 classes? Try it out with training_areas.geojson.