从多指数值计数绘制热图

发布于 2025-02-07 05:19:35 字数 561 浏览 0 评论 0原文

我有一个带有多个列的熊猫数据框,其中两个是类型的bool,称为resultpredict

我使用以下代码获取一个多索引序列:

df.value_counts()

结果预测
真实88628
FALSE 995 FALSE995
FALSE35FALSE
返回我希望

能够使用Seaborn或Matplotlib绘制此混乱矩阵。

I have a pandas DataFrame with multiple columns, where two of them are of type bool and called result and predict.

I use the following code to get a multi-indexed series:

df.value_counts()

Which returns:

resultpredict
TrueTrue886
False995
FalseTrue35
False28

I want to be able to plot this confusion matrix using seaborn or matplotlib.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋千易 2025-02-14 05:19:35

宁愿使用 crosstab

import seaborn as sns

ct = pd.crosstab(df['result'], df['predict'])
print(ct)

sns.heatmap(ct)

Rather use crosstab:

import seaborn as sns

ct = pd.crosstab(df['result'], df['predict'])
print(ct)

sns.heatmap(ct)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文