0

Question:- My Heatmap is not showing data properly at top and bottom of the heatmap.

Issue Heatmap for your review

from sklearn.datasets import fetch_20newsgroups

data = fetch_20newsgroups()
data.target_names
categories = ['talk.religion.misc', 'soc.religion.christian',
              'sci.space', 'comp.graphics']
train = fetch_20newsgroups(subset='train', categories=categories)
test = fetch_20newsgroups(subset='test', categories=categories)

from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.naive_bayes import MultinomialNB
from sklearn.pipeline import make_pipeline

model = make_pipeline(TfidfVectorizer(), MultinomialNB())

model.fit(train.data, train.target)
labels = model.predict(test.data)

import seaborn as sns
import matplotlib.pyplot as plt
from sklearn.metrics import confusion_matrix
mat = confusion_matrix(test.target, labels)

plt.subplots(figsize=(7, 5))

sns.heatmap(mat.T, square=True, annot=True, fmt='d', cbar=False,
            xticklabels=train.target_names, yticklabels=train.target_names,linewidths=.5)
#plt.figure(figsize = (32,10))
plt.xlabel('true label')
plt.ylabel('predicted label')
desertnaut
  • 57,590
  • 26
  • 140
  • 166
  • This should be solved installing the latest versions of matplotlib and seaborn. – JohanC Apr 25 '20 at 20:52
  • Does this answer your question? [matplotlib/seaborn: first and last row cut in half of heatmap plot](https://stackoverflow.com/questions/56942670/matplotlib-seaborn-first-and-last-row-cut-in-half-of-heatmap-plot) – JohanC Apr 25 '20 at 20:54

0 Answers0