Skip to content

Instantly share code, notes, and snippets.

@NickyAlan
Created May 18, 2022 15:38
Show Gist options
  • Save NickyAlan/6ce205d8de44ebf8ec9b2570babcdd93 to your computer and use it in GitHub Desktop.
Save NickyAlan/6ce205d8de44ebf8ec9b2570babcdd93 to your computer and use it in GitHub Desktop.
def plot_boundaries(model,xlabel,ylabel,title,figsize):
h = .02 # step size in the mesh
x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1
y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1
xx, yy = np.meshgrid(np.arange(x_min, x_max, h),
np.arange(y_min, y_max, h))
plt.figure(figsize=figsize)
Z = model.predict(np.c_[xx.ravel(), yy.ravel()])
Z = Z.reshape(xx.shape)
plt.contourf(xx, yy, Z, cmap=plt.cm.coolwarm, alpha=0.8)
plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.coolwarm)
plt.xlabel(xlabel)
plt.ylabel(ylabel)
plt.xlim(xx.min(), xx.max())
plt.ylim(yy.min(), yy.max())
plt.xticks(())
plt.yticks(())
plt.title(title)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment