【问题标题】:How can I get the numbers for the correlation matrix from Pandas Profiling如何从 Pandas Profiling 中获取相关矩阵的数字
【发布时间】:2021-02-13 16:01:39
【问题描述】:

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

有没有简单的方法来提取数字?

【问题讨论】:

    标签: pandas-profiling


    【解决方案1】:

    从文档开始有点难以追踪;具体来说 从report structure,然后挖掘到下面的函数get_correlation_items(summary),然后进入源代码并查看它的用法,我们得到这个调用,本质上是在摘要中loops over each of the correlation types,以获得摘要对象,我们可以找到接下来,如果我们查找调用者,我们会发现它是get_report_structure(summary),如果我们尝试找到如何获取summary arg,我们会发现它只是description_set 属性,如here 所示。

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

    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"]
    
    a    0.000000
    b    0.112446
    c    0.289983
    d    0.000000
    e    1.000000
    Name: e, dtype: float64
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-09-27
      • 2019-10-20
      • 2019-09-26
      • 1970-01-01
      • 1970-01-01
      • 2022-08-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多