Last active
April 9, 2023 13:47
-
-
Save konverner/b46a1a49ba9fa0679020636d314b307b to your computer and use it in GitHub Desktop.
visualise classifier borders
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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