在seaborn中绘制回归时如何获得数值拟合结果? [英] How to get the numerical fitting results when plotting a regression in seaborn?

查看:67
本文介绍了在seaborn中绘制回归时如何获得数值拟合结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用 Python 中的 seaborn 库来绘制线性回归的结果,有没有办法找出回归的数值结果?例如,我可能想知道拟合系数或拟合的 R2.

If I use the seaborn library in Python to plot the result of a linear regression, is there a way to find out the numerical results of the regression? For example, I might want to know the fitting coefficients or the R2 of the fit.

我可以使用底层 statsmodels 界面重新运行相同的拟合,但这似乎是不必要的重复工作,无论如何我希望能够比较结果系数以确保数值结果相同正如我在情节中看到的那样.

I could re-run the same fit using the underlying statsmodels interface, but that would seem to be unnecessary duplicate effort, and anyway I'd want to be able to compare the resulting coefficients to be sure the numerical results are the same as what I'm seeing in the plot.

推荐答案

没有办法做到这一点.

在我看来,要求可视化库为您提供统计建模结果是倒退的.statsmodels 是一个建模库,可让您拟合模型,然后绘制与您拟合的模型完全对应的图.如果你想要精确的对应关系,这个操作顺序对我来说更有意义.

In my opinion, asking a visualization library to give you statistical modeling results is backwards. statsmodels, a modeling library, lets you fit a model and then draw a plot that corresponds exactly to the model you fit. If you want that exact correspondence, this order of operations makes more sense to me.

您可能会说但是 statsmodels 中的绘图没有 seaborn 那么多的美学选项".但我认为这是有道理的——statsmodels 是一个建模库,有时在建模服务中使用可视化.seaborn 是一个可视化库,有时在可视化服务中使用建模.专精固然好,什么都做不好.

You might say "but the plots in statsmodels don't have as many aesthetic options as seaborn". But I think that makes sense — statsmodels is a modeling library that sometimes uses visualization in the service of modeling. seaborn is a visualization library that sometimes uses modeling in the service of visualization. It is good to specialize, and bad to try to do everything.

幸运的是,seabornstatsmodels 都使用 整洁的数据.这意味着您确实需要很少的工作重复来通过适当的工具获得图和模型.

Fortunately, both seaborn and statsmodels use tidy data. That means that you really need very little effort duplication to get both plots and models through the appropriate tools.

这篇关于在seaborn中绘制回归时如何获得数值拟合结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆