【发布时间】:2017-07-04 20:34:45
【问题描述】:
问题陈述:
我在 pandas 数据框中有一些不错的数据。我想对其进行简单的线性回归:
使用 statsmodels,我执行回归。现在,我如何获得我的情节?我试过 statsmodels 的plot_fit 方法,但情节有点古怪:
我希望得到一条代表回归实际结果的水平线。
Statsmodels 有一个 variety of methods for plotting regression (a few more details about them here) 但它们似乎都不是超级简单的“只需在数据之上绘制回归线”——plot_fit 似乎是最接近的东西。
问题:
- 上面的第一张图片来自pandas的plot函数,它返回一个
matplotlib.axes._subplots.AxesSubplot。我可以轻松地将回归线覆盖到该图上吗? - statsmodels 中是否有我忽略的函数?
- 有没有更好的方法来组合这个数字?
两个相关问题:
- Plotting Pandas OLS linear regression results
- Getting the regression line to plot from a Pandas regression
似乎都没有一个好的答案。
样本数据
根据@IgorRaush 的要求
motifScore expression
6870 1.401123 0.55
10456 1.188554 -1.58
12455 1.476361 -1.75
18052 1.805736 0.13
19725 1.110953 2.30
30401 1.744645 -0.49
30716 1.098253 -1.59
30771 1.098253 -2.04
abline_plot
我试过这个,但它似乎不起作用......不知道为什么:
【问题讨论】:
-
请发布一个示例数据集(看起来你的数据集很小,所以你可以发布整个内容)。一般来说,我会推荐
seaborn.regplot,如果你可以接受这种依赖,它会满足你的需求。 -
@IgorRaush 见上文
标签: pandas matplotlib statsmodels