加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

Python – Seaborn Pairplot Pearsons P统计

发布时间:2020-12-20 11:47:42 所属栏目:Python 来源:网络整理
导读:我一直在从事 python / seaborn / scipy.stats / matplotlib.pyplot等新手的数据分析工作. Seaborn Correlation Coefficient on PairGrid ?这个链接帮助我通过皮尔森R得分呈现我的变量之间的关系. 然而,由于Pearsons测试的输出也应具有p值以指示统计显着性,
我一直在从事 python / seaborn / scipy.stats / matplotlib.pyplot等新手的数据分析工作.

Seaborn Correlation Coefficient on PairGrid
?这个链接帮助我通过皮尔森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.未提供的数据是已过滤以删除异常值的数据帧

任何想法都是神奇的

问候

解决方法

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

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

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

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

结果

seaborn pairplot

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读