微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何从Pandas Profiling获取相关矩阵的数字

如何解决如何从Pandas Profiling获取相关矩阵的数字

我真的很喜欢热图,但是我需要的是热图后面的数字(AKA相关矩阵)。

Heatmap example

是否有一种简单的方法提取数字?

解决方法

从文档开始很难追踪。特别 从report structure开始,然后深入研究以下函数get_correlation_items(summary),然后进入源代码并查看其用法,我们得出了本质上loops over each of the correlation types的调用,以获取摘要摘要对象,我们可以找到以下内容:如果我们查找调用者,我们会发现它是get_report_structure(summary);如果我们尝试找到如何获取summary arg,就会发现它仅仅是{{1} }属性,如here所示。

鉴于以上所述,我们现在可以使用2.9.0版执行以下操作:

description_set
import numpy as np
import pandas as pd
from pandas_profiling import ProfileReport

df = pd.DataFrame(
    np.random.rand(100,5),columns=["a","b","c","d","e"]
)

profile = ProfileReport(df,title="StackOverflow",explorative=True)

correlations = profile.description_set["correlations"]
print(correlations.keys())

要查看特定的相关性,请执行以下操作:

dict_keys(['pearson','spearman','kendall','phi_k'])
correlations["phi_k"]["e"]

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。