如何解决通过泰尔森估计器在熊猫时间序列中绘制回归线的置信区间
我正在处理时间序列数据帧,例如:
df = pd.DataFrame({'year':[ '1990','1991','1992','1993','1994','1995','1996','1997','1998','1999','2000'],'count':[96,184,148,154,160,149,124,274,322,301,300]})
我有兴趣使用 Theil-Sen's slope estimator
和 Scipy
中的函数找到回归线
https://docs.scipy.org/doc/scipy-0.15.1/reference/generated/scipy.stats.mstats.theilslopes.html
如以下 code
片段:
from scipy import stats
x = df['year'].astype(float)
y = df['count']
res = stats.theilslopes(y,x,0.90)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x,y,'b.')
ax.plot(x,res[1] + res[0] * x,'r-')
plt.ylabel('count')
plt.xlabel('year')
plt.show()
我可以找到 Theil-Sen's regression line
,但是在添加用于可视化 confidence interval
的代码时,可视化有些不切实际。
ax.plot(x,res[1] + res[2] * x,'r--')
ax.plot(x,res[1] + res[3] * x,'r--')
有什么办法,我可以用 theil-sen's slope estimator
和 confidence interval
获得可视化效果,如下图所示:
您的帮助将不胜感激。 谢谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。