from sklearn metrics cluster import adjusted_rand_score xy make_moons(n_samples= noise= random_state= rescale the data to zero mean and unit variance scaler standardscaler(scaler fit(xx_scaled scaler transform(xfigaxes plt subplots( figsize=( )subplot_kw={'xticks'()'yticks'()}make list of algorithms to use algorithms [kmeans(n_clusters= )agglomerativeclustering(n_clusters= )dbscan()create random cluster assignment for reference random_state np random randomstate(seed= random_clusters random_state randint(low= high= size=len( )plot random assignment axes[ scatter(x_scaled[: ]x_scaled[: ] =random_clusterscmap=mglearn cm = axes[ set_title("random assignment ari{ }formatadjusted_rand_score(yrandom_clusters))for axalgorithm in zip(axes[ :]algorithms)plot the cluster assignments and cluster centers clusters algorithm fit_predict(x_scaledax scatter(x_scaled[: ]x_scaled[: ] =clusterscmap=mglearn cm = ax set_title("{ari{ }format(algorithm __class__ __name__adjusted_rand_score(yclusters))figure - comparing random assignmentk-meansagglomerative clusteringand dbscan on the two_moons dataset using the supervised ari score the adjusted rand index provides intuitive resultswith random cluster assignment having score of and dbscan (which recovers the desired clustering perfectlyhaving score of unsupervised learning and preprocessing