Skip to main content

Supervised classifiers

Once spectra carry optical water type labels, any supervised classifier can learn to assign new spectra to them. The labels may come from a published scheme, from clustering, or from expert judgement. Random forests (Breiman 2001), support vector machines and neural networks have all been used, for example for Spanish inland waters from Sentinel-2 MSI reflectance (Remote Sensing 14, 5568, 2022, doi:10.3390/rs14215568).

SupervisedClassifier wraps a scikit-learn classifier that has predict_proba, and gives it the common interface. Spectra are normalised first, as in the other classifiers. The memberships are the class probabilities, so they sum to one.

Using the classifier

The example learns the ten Bi & Hieronymi types directly from the OLCI spectra of their training set, with half of the spectra held back for testing.

import numpy as np
from fuzzy_water.classify import SupervisedClassifier
from fuzzy_water.training import load_bi_hieronymi

bh = load_bi_hieronymi("owt_BH2024_training_data_olci.nc", max_wavelength=710)
rng = np.random.default_rng(0)
train = rng.random(bh.sizes["sample"]) < 0.5
rf = SupervisedClassifier(random_state=0).fit(bh.isel(sample=train),
                                              bh["owt"].values[train])
pred = rf.predict(bh.isel(sample=~train))
print(f"agreement on held-out spectra: {np.mean(pred.values == bh['owt'].values[~train]):.3f}")
agreement on held-out spectra: 0.885

Any other estimator can be passed in.

from sklearn.neural_network import MLPClassifier

mlp = SupervisedClassifier(MLPClassifier(hidden_layer_sizes=(64, 64), max_iter=500))

Choices and notes

  • The default estimator is a random forest with 300 trees. It needs no feature scaling and gives smooth class probabilities.
  • Probabilities sum to one, so they do not flag spectra unlike every class. Screen spectra with QWIP, or compare with the membership sum of a chi-squared classifier.
  • The fitted estimator is not an array and cannot be written to a netCDF class set. to_netcdf raises an error; store the classifier with joblib or pickle.

References

Breiman, L. 2001. Random forests. Machine Learning 45: 5–32. doi:10.1023/A:1010933404324