July 2017
Intermediate to advanced
382 pages
9h 13m
English
Although OpenCV does not provide an implementation of agglomerative hierarchical clustering, it is a popular algorithm that should, by all means, belong to our machine learning repertoire.
We start out by generating 10 random data points, just like in the previous figure:
In [1]: from sklearn.datasets import make_blobs... X, y = make_blobs(random_state=100, n_samples=10)
Using the familiar statistical modeling API, we import the AgglomerativeClustering algorithm and specify the desired number of clusters:
In [2]: from sklearn import cluster... agg = cluster.AgglomerativeClustering(n_clusters=3)
Fitting the model to the data works, as usual, via the fit_predict method:
In [3]: labels ...
Read now
Unlock full access