Machine Learning#

The HV SDK provides a number of convenience functions for making working with certain ML models easier and more efficient.

PCA#

Projection methods like PCA can be computed more efficiently by using the SDK’s built-in hsi.HSImage.dot() method. We provide hsi.ml.pca_helper() for users to be able to easily wrap any pca-like model.

from hsi.ml import pca_helper
from sklearn.decomposition import PCA

model = PCA()
model.fit(...) # Training step

hs_model = pca_helper(model)

img = hsi.open(<path>)

# Here, the prediction function is created.
out = hs_model(img)

# The calculation is only applied when requested, similar to other operations
result = out.to_numpy()

The only requirements to the “pca-like” model, is that prediction uses the equation O = (I - mu) * W^T, where I is the input image, mu is the mean of the model, and W is the transpose of the components_ of the model.

For scikit-learn, the supported model types include PCA, FactorAnalysis, FastICA, SparsePCA, etc.