Last active
January 21, 2020 09:41
-
-
Save whiledoing/143dc4b8be7dacb22bb971dcaa5678ac to your computer and use it in GitHub Desktop.
[seaborn-snippets] seaborn snippets #python #seaborn #visualization
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
from sklearn.datasets import load_digits | |
digits = load_digits() | |
# split data | |
from sklearn.model_selection import train_test_split | |
X_train, X_test, y_train, y_test = train_test_split(digits.data, digits.target, shuffle=True) | |
# use Gaussian Naive Bayes | |
from sklearn.naive_bayes import GaussianNB | |
model = GaussianNB() | |
model.fit(X_train, y_train) | |
y_model = model.predict(X_test) | |
# get confusion matrix | |
from sklearn.metrics import confusion_matrix | |
mat = confusion_matrix(y_test, y_model) | |
# visualize confusion matrix using heatmap | |
with plt.style.context('ggplot'): | |
ax = sns.heatmap(mat, annot=True, square=True, cbar=False, cmap='GnBu', linewidths=.3); | |
ax.invert_yaxis(); | |
ax.xaxis.set_ticklabels(ax.xaxis.get_ticklabels(), rotation=-45); | |
ax.yaxis.set_ticklabels(ax.yaxis.get_ticklabels(), rotation=45); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment