【问题标题】:correlation in statsmodel using python使用python的statsmodel中的相关性
【发布时间】:2013-03-06 13:45:03
【问题描述】:

你能帮我找到这两个列表在 python 中导入 stats-model 的相关性吗?

  a=[1.0,2.0,3.0,2.0]
  b=[789.0,786.0,788.0,785.0]

使用一些内置函数

【问题讨论】:

    标签: python-2.7 statsmodels


    【解决方案1】:
    >>> import numpy as np
    >>> a = np.array([1.0,2.0,3.0,2.0])
    >>> b = np.array([789.0,786.0,788.0,785.0])
    >>> np.corrcoef(a,b)
    array([[ 1.       , -0.2236068],
           [-0.2236068,  1.       ]])
    

    只需使用索引来提取正确的:

    np.corrcoef(a,b)[0,1]
    

    【讨论】:

    • 当我不使用这个 numpy 并找到相关性时,我得到 c = [1] 0.223608,如何使用 numpy 获得类似的输出
    • 我编辑了答案,但实际上你应该自己做最少的工作。这是微不足道的。
    猜你喜欢
    • 1970-01-01
    • 2014-08-10
    • 2021-06-04
    • 2015-12-12
    • 2015-05-23
    • 1970-01-01
    • 2019-05-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多