【问题标题】:Seaborn Pairplot Pearsons P statisticSeaborn Pairplot Pearsons P 统计量
【发布时间】:2016-03-19 05:42:22
【问题描述】:

我作为新手一直在 python/seaborn/scipy.stats/matplotlib.pyplot 等完成数据分析任务

Seaborn Correlation Coefficient on PairGrid 这个链接帮助我通过 pearsons R 分数呈现我的变量之间的关系。 然而,由于 Pearsons 测试的输出也应该有一个 p 值以指示统计显着性,因此我正在寻找一种将 P 值添加到我的绘图上的注释的方法。

g = sns.pairplot(unoutlieddata, vars=['bia', 'DW', 'HW', 'jackson', 'girths'], kind="reg")

def corrfunc(x, y, **kws):
    r, _ = sps.pearsonr(x, y)
    ax = plt.gca()
    ax.annotate("r = {:.2f}".format(r),
                xy=(.1, .9), xycoords=ax.transAxes)

g.map(corrfunc)
sns.plt.show()

显示的是我提供的链接格式的代码。 sps=scipy.stats。 unoutlied data 是经过过滤以去除异常值的数据框

任何想法都会很棒

问候

【问题讨论】:

  • 感谢编辑这个问题的人,所以它也很有意义:对不起,它最初是粗略的格式:我的第一个问题,正如我所说的我是新手

标签: python matplotlib scipy seaborn


【解决方案1】:

不确定是否有人会看到这个,但在与了解更多的人交谈后,答案如下

代码

import matplotlib.pyplot as plt
import seaborn as sns
from scipy.stats import pearsonr

def corrfunc(x, y, **kws):
    (r, p) = pearsonr(x, y)
    ax = plt.gca()
    ax.annotate("r = {:.2f} ".format(r),
                xy=(.1, .9), xycoords=ax.transAxes)
    ax.annotate("p = {:.3f}".format(p),
                xy=(.4, .9), xycoords=ax.transAxes)

df = sns.load_dataset("iris")
df = df[df["species"] == "setosa"]
graph = sns.pairplot(df)
graph.map(corrfunc)
plt.show()

结果

【讨论】:

  • 如果您附上输出图进行说明会很有帮助。
猜你喜欢
  • 2016-08-25
  • 2021-02-04
  • 2019-07-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多