【发布时间】:2020-04-08 01:55:08
【问题描述】:
使用 seaborn 绘制热图时,数字会打印在热图的边界上。我已经使用相同的代码多次绘制热图。它曾经运行良好,但我正面临这个错位问题。
使用的代码
#Defining a custom function
def get_confusion_matrix(clf,X_te,y_test):
y_pred = clf.predict(X_te)
df_cm = pd.DataFrame(confusion_matrix(y_test, y_pred), range(2),range(2))
df_cm.columns = ['Predicted NO','Predicted YES']
df_cm = df_cm.rename({0: 'Actual NO', 1: 'Actual YES'})
sns.set(font_scale=1.4)#for label size
sns.heatmap(df_cm, annot=True,annot_kws={"size": 16}, fmt='d',cmap="YlGnBu", linewidths=5)
#Using the function to plot the heatmap
get_confusion_matrix(model_s1,X_tr,y_train_1)
【问题讨论】:
-
请同时发布您用来绘制绘图的代码。这将有助于理解问题。
-
@DishinHGoyani 感谢您的建议。我已经添加了代码 sn-p。
-
您使用的是哪个版本的 matplotlib?如果您使用的是 3.1.1,请尝试下载上次更新或将其降级到 3.1.0,边界存在一些问题,但我不知道它是否也与您的问题有关。如我所见,您的热图有点可爱github.com/matplotlib/matplotlib/issues/14675
标签: python machine-learning seaborn data-science heatmap