colors=['#4EACC5','#FF9C34','#4E9A06']# We want to have the same colors for the same cluster from the# MiniBatchKMeans and the KMeans algorithm. Let's pair the cluster centers per# closest one.k_means_cluster_centers=np.sort(k_means.cluster_centers_,axis=0)mbk_means_cluster_centers=np.sort(mbk.cluster_centers_,axis=0)k_means_labels=pairwise_distances_argmin(X,k_means_cluster_centers)mbk_means_labels=pairwise_distances_argmin(X,mbk_means_cluster_centers)order=pairwise_distances_argmin(k_means_cluster_centers,mbk_means_cluster_centers)fig=tools.make_subplots(rows=1,cols=3,print_grid=False,subplot_titles=('KMeans<br>train time: %.2fs\ninertia: %f'%(t_mini_batch,mbk.inertia_),'MiniBatchKmeans<br>train time: %.2fs\ninertia: %f'%(t_mini_batch,mbk.inertia_),'Difference'))

# Initialise the different array to all Falsedifferent=(mbk_means_labels==4)forkinrange(n_clusters):different+=((k_means_labels==k)!=(mbk_means_labels==order[k]))identic=np.logical_not(different)difference1=go.Scatter(x=X[identic,0],y=X[identic,1],showlegend=False,mode='markers',marker=dict(color='#bbbbbb',size=4))difference2=go.Scatter(x=X[different,0],y=X[different,1],showlegend=False,mode='markers',marker=dict(color='magenta',size=4))fig.append_trace(difference1,1,3)fig.append_trace(difference2,1,3)fig['layout']['xaxis3'].update(showticklabels=False,ticks='',zeroline=False,showgrid=False)fig['layout']['yaxis3'].update(showticklabels=False,ticks='',zeroline=False,showgrid=False)