Python 在seaborn regplot中显示回归方程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33490833/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 13:26:31  来源:igfitidea点击:

Display regression equation in seaborn regplot

pythonregressionseaborn

提问by Vikram Josyula

Does anyone know how to display the regression equation in seaborn using sns.regplot or sns.jointplot? regplot doesn't seem to have any parameter that you can be pass to display regression diagnostics, and jointplot only displays the pearson R^2, and p-value. I'm looking for a way to see the slope coefficient, standard error, and intercept as well.

有谁知道如何使用 sns.regplot 或 sns.jointplot 在 seaborn 中显示回归方程?regplot 似乎没有任何可以传递来显示回归诊断的参数,并且jointplot 只显示pearson R^2 和p 值。我正在寻找一种方法来查看斜率系数、标准误差和截距。

Thanks

谢谢

回答by Khris

A late and partial answer. I had the problem of just wanting to get the data of the regression line and I found this:

一个迟到的部分答案。我遇到了只想获取回归线数据的问题,我发现了这个:

When you have this plot:

当你有这个情节时:

f = mp.figure()
ax = f.add_subplot(1,1,1)
p = sns.regplot(x=dat.x,y=ydat,data=dat,ax=ax)

Then phas a method get_lines()which gives back a list of line2Dobjects. And a line2Dobject has methods to get the desired data:

然后p有一个get_lines()返回line2D对象列表的方法。并且line2D对象具有获取所需数据的方法:

So to get the linear regression data in this example, you just need to do this:

所以要得到这个例子中的线性回归数据,你只需要这样做:

p.get_lines()[0].get_xdata()
p.get_lines()[0].get_ydata()

Those calls return each a numpyarray of the regression line data points which you can use freely.

这些调用返回每个numpy您可以自由使用的回归线数据点数组。

Using p.get_children()you get a list of the individual elements of the plot.

使用p.get_children()您可以获得绘图的各个元素的列表。

The path information of the confidence interval plot can be found with:

置信区间图的路径信息可以通过以下方式找到:

p.get_children()[1].get_paths()

It's in the form of tuples of data points.

它采用数据点元组的形式。

Generally a lot can be found by using the dir()command on any Python object, it just shows everything that's in there.

通常,通过dir()在任何 Python 对象上使用该命令可以找到很多内容,它只显示其中的所有内容。

回答by millikan

In 2015, the lead developer for seaborn replied to a feature request asking for access to the statistical values used to generate plots by saying, "It is not available, and it will not be made available."

2015 年,seaborn 的首席开发人员回复了一项功能请求,要求访问用于生成绘图的统计值,他说:“它不可用,也不会提供。”

So, unfortunately, this feature does not exist in seaborn, and seems unlikely to exist in the future.

所以,不幸的是,这个特性在 seaborn 中不存在,而且在未来似乎不太可能存在。

Update: in March 2018, seaborn's lead developer reiterated his oppositionto this feature. He seems... uninterested in further discussion.

更新:2018 年 3 月,seaborn 的首席开发人员重申了他对该功能的反对。他似乎……对进一步讨论不感兴趣。