python - 混淆矩阵Python中数字的位置不合适
问题描述
我有这样的代码:
plt.figure(figsize=(8,5))
confusion_matrix = pd.crosstab(y_test, predictions, rownames=["Observed"], colnames=["Anticipated"])
sns.heatmap(confusion_matrix, annot=True, fmt= "d")
plt.show()
解决方案
如datascience.stackexchange.com 上的这篇文章所示,matplotlib 3.1.1坏了sns.heatmap()
。那里的答案建议降级到matplotlib 3.1.0。但是我已经在我的机器上安装了 3.1.2 并且它正在工作。因此,您现在也许可以升级。
y_test = np.array(
[
"foo", "foo", "foo", "foo",
"bar", "bar", "bar", "bar",
"foo", "foo", "foo"
], dtype=object
)
predictions = np.array(
[
"one", "one", "one", "two",
"one", "one", "one", "two",
"two", "two", "one"
], dtype=object
)
plt.figure(figsize=(8, 5))
confusion_matrix = pd.crosstab(
y_test, predictions, rownames=["Observed"], colnames=["Anticipated"]
)
sns.heatmap(confusion_matrix, annot=True, fmt="d")
plt.show()
这是pip list
使用相关软件包的结果。
Package Version Location
------------------ --------- -------------------------------------
matplotlib 3.1.2
pandas 0.25.1
seaborn 0.9.0
推荐阅读
- flutter - Show CircularProgressIndicator in front in Flutter
- java - JSR223 PreProcessor ScriptException:groovy.lang.MissingPropertyException:jmeter中没有这样的属性
- vsto - Outlook 插件:自定义功能区在主应用程序窗口中不可见,尽管 RibbonType 包含在 Microsoft.Outlook.Explorer 中
- feathersjs - 有没有一种方法可以通过在羽毛 js 中自定义服务来编写 mongodb 聚合管道
- python - tox 没有找到 numpy
- yacc - 如何在`bison/yacc`中重新定义`YYSTYPE`?
- javascript - 如何使用 JS 在 HTMl 中选择元素,为什么在这种情况下函数不起作用?
- c# - 为什么 awaiter.IsCompleted 总是返回 false?
- python - python中的线程调度程序
- django - 如何在 django 中过滤来自 3 个不同模型的值