Seaborn,pandas,statsmodule的综合使用(高级编程技术 week14)
这次我们完成的题目来源于该网站:
part 1
For each of the four datasets…
- Compute the mean and variance of both x and y
- Compute the correlation coefficient between x and y
- Compute the linear regression line: y=β0+β1x+ϵ (hint: use statsmodels and look at the Statsmodels notebook)
使用到的工具
在计算数据的统计学数据时,我使用到了numpy库相关的函数,如np.average()
, np.var()
,np.corrcoef()
等,对statsmodule库也有了初步的了解。
代码展示
data_stats = {}
# 打印四个数据集的相关统计数据,计算并画出四个数据集的拟合曲线
for i in range(0, 4):
# 获得对应数据集数据
data = anscombe[anscombe.data == i]
# 计算平均值,方差,相关系数,并使用json