Skip to content

Instantly share code, notes, and snippets.

@whiledoing
Last active January 21, 2020 09:41
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 whiledoing/143dc4b8be7dacb22bb971dcaa5678ac to your computer and use it in GitHub Desktop.
Save whiledoing/143dc4b8be7dacb22bb971dcaa5678ac to your computer and use it in GitHub Desktop.
[seaborn-snippets] seaborn snippets #python #seaborn #visualization
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