Source code for libpyhat.clustering.cluster

from sklearn.cluster import KMeans, SpectralClustering


# This function runs clustering on a data frame full of spectra. Different
# algorithms can be chosen


[docs] def cluster(df, col, method, params, kws): do_cluster = None if method == "K-Means": do_cluster = KMeans(*params, **kws) if method == "Spectral": do_cluster = SpectralClustering(*params, **kws) if do_cluster is None: print("No valid clustering method selected!") else: do_cluster.fit(df[col]) df[(method, method + "-Cluster")] = do_cluster.labels_ + 1 return df