Reputation:
Is there any way I can move the xLabel(predicted label) 0, 1, to the top of the confusion matrix? Appreciate any help.
from sklearn.metrics import accuracy_score
plt.figure(figsize=(6,4))
sns.heatmap(cm_rf, annot=True, fmt="d")
plt.title('Random Forest Tree \nAccuracy:{0:.3%}\n'.format(accuracy_score(test_y, predict_rf_y)))
plt.ylabel('True label')
plt.xlabel('Predicted label')
plt.show()
Upvotes: 6
Views: 9829
Reputation: 296
The properties you're looking for are ax.xaxis.set_ticks_position('top')
and ax.xaxis.set_label_position('top')
. For example :
f, ax = plt.subplots(figsize=(6, 4))
sns.heatmap(np.random.randint(0, 3, size=(2, 2)), annot=True, fmt="d")
ax.set_title('Random Forest Tree \nAccuracy:{format}\n', y=1.08)
ax.set_ylabel('True label')
ax.set_xlabel('Predicted label')
ax.xaxis.set_ticks_position('top')
ax.xaxis.set_label_position('top')
Hope this helps
Upvotes: 18