Agglomerative clustering in scikit-learn

Let's consider a more complex dummy dataset with 8 centers:

>>> nb_samples = 3000>>> X, _ = make_blobs(n_samples=nb_samples, n_features=2, centers=8, cluster_std=2.0)

A graphical representation is shown in the following figure:

We can now perform an agglomerative clustering with different linkages (always keeping the Euclidean distance) and compare the results. Let's start with a complete linkage (AgglomerativeClustering uses the method fit_predict() to train the model and transform the original dataset):

from sklearn.cluster import AgglomerativeClustering>>> ac = AgglomerativeClustering(n_clusters=8, ...

Get Machine Learning Algorithms now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.