Jupyter Notebook(6.6作业)
2018-06-11 本文已影响0人
Pessimist_34ad
安装与启动
安装Ipython与Jupyter。
pip install --upgrade Ipython
pip install --upgrade Jupyter
此外还要安装python下的用于数据分析的库pandas、seaborn、statsmodels。
如果pip默认的源比较慢,可以自行指定下载源。如指定使用阿里云的镜像下载jupyter:
pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com jupyter
把对应的路径设置为环境变量后,输入以下指令运行。
jupyter notebook --notebook-dir="YourDirectory"
在我的电脑上使用的文件路径为E:\jupyter,对应的指令为
jupyter notebook --notebook-dir="E:\jupyter"
此外,我把作业需要的数据文件anscombe.csv
也放在该目录下。
启动后自动打开了一个浏览器,点击右上角New->Python3可以打开一个新的Python3文件。
首先先引入各类库:

读取数据:

计算x和y的平均值和方差:

计算x和y之间的关联系数(correlation coefficient):

计算线性回归方程:


对应参数为:

即β0 = 3.0013, β1 = 0.4999
图形如下:

使用Seaborn可视化数据:

参考资料:
Statsmodels 统计包之 OLS 回归
Simple and Multiple Linear Regression in Python