Skip to content

Instantly share code, notes, and snippets.

@NickyAlan
Created May 29, 2022 18:16
Show Gist options
  • Save NickyAlan/0cfa98ddcd3132a2f86f5b6233d50abf to your computer and use it in GitHub Desktop.
Save NickyAlan/0cfa98ddcd3132a2f86f5b6233d50abf to your computer and use it in GitHub Desktop.
def plot_decision_boundaries(clusterer, X, resolution=500, show_centroids=True,
show_xlabels=True, show_ylabels=True):
mins = X.min(axis=0) - 0.1
maxs = X.max(axis=0) + 0.1
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)
#cmap
plt.contourf(Z, extent=(mins[0], maxs[0], mins[1], maxs[1]),
cmap="Pastel2")
#boundaries
plt.contour(Z, extent=(mins[0], maxs[0], mins[1], maxs[1]),
linewidths=.5, colors='k')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment