Skip to content

Instantly share code, notes, and snippets.

@konverner
Last active April 9, 2023 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save konverner/b46a1a49ba9fa0679020636d314b307b to your computer and use it in GitHub Desktop.
Save konverner/b46a1a49ba9fa0679020636d314b307b to your computer and use it in GitHub Desktop.
visualise classifier borders
X_train = ... # (n,2) numpy array dataset
# Create a meshgrid
x_min, x_max = X_train[:, 0].min() - 1, X_train[:, 0].max() + 1
y_min, y_max = X_train[:, 1].min() - 1, X_train[:, 1].max() + 1
xx, yy = np.meshgrid(np.arange(x_min, x_max, 0.1),
np.arange(y_min, y_max, 0.1))
# Make predictions on the meshgrid
preds = clf.predict(np.c_[xx.ravel(), yy.ravel()])
Z = preds.reshape(xx.shape)
# Visualize the boundaries
plt.contourf(xx, yy, Z, cmap=plt.cm.Paired, alpha=0.8)
plt.scatter(X_train.values[:, 0], X_train[:, 1], c=y_train, cmap=plt.cm.Paired)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment