Decision boundary for KMeans clustering algorithm Below code is used for plotting decision boundary for KMeans clustering. I understand contour in general, my question is, how does plot (contour method) know where to draw decision boundary based on predicted Z values, without knowing X and Y coordinates?
 xx, yy = np.meshgrid(np.linspace(mins[0], maxs[0], resolution),
                         np.linspace(mins[1], maxs[1], resolution))
 Z = clusterer.predict(np.c_[xx.ravel(), yy.ravel()])
 Z = Z.reshape(xx.shape)

 plt.contourf(Z, extent=(mins[0], maxs[0], mins[1], maxs[1]),
                cmap=&quot;Pastel2&quot;)
 plt.contour(Z, extent=(mins[0], maxs[0], mins[1], maxs[1]),
                linewidths=1, colors='k')
Can you post a picture of the plot here and maybe some reproducible code? My understanding with the info you've given is that the contour plot is not actually plotting a decision boundary. In fact, I think its not really helpful to think about k-means as producing a decision boundary. At the end of iteration you have K centroids and 'classify' points based on which centroid it is closest to.