jupyter notebook (别称ipython notebook)是一个基于网页的交互式笔记本,支持40多种编程语言。支持创建和共享包含实时代码、方程式、可视化和叙述性文本的文档。


安装jupyter notebook

具体安装方式官网有详细介绍 install jupyter,我选择了通过anaconda安装

anaconda是一个python的开源科学计算平台,支持linux、mac、windows系统,内置个各种常用科学计算包,提供包管理功能和环境管理功能,解决了多版本python并存造成的各种问题,适合初学者和懒人使用

下载可以通过anaconda 的官方下载地址,不过速度真的太慢了……推荐使用清华大学镜像站下载

有关jupyter的各种用法可以查看这个博客, 或者直接查阅官方文档


作业题目

Anscombe's quartet comprises of four datasets, and is rather famous. Why?You'll find out in this exercise.

Anscombe’s Quartet
I II III IV
x y x y x y x y
10.0 8.04 10.0 9.14 10.0 7.46 8.0 6.58
8.0 6.95 8.0 8.14 8.0 6.77 8.0 5.76
13.0 7.58 13.0 8.74 13.0 12.74 8.0 7.71
9.0 8.81 9.0 8.77 9.0 7.11 8.0 8.84
11.0 8.33 11.0 9.26 11.0 7.81 8.0 8.47
14.0 9.96 14.0 8.10 14.0 8.84 8.0 7.04
6.0 7.24 6.0 6.13 6.0 6.08 8.0 5.25
4.0 4.26 4.0 3.10 4.0 5.39 19.0 12.50
12.0 10.84 12.0 9.13 12.0 8.15 8.0 5.56
7.0 4.82 7.0 7.26 7.0 6.42 8.0 7.91
5.0 5.68 5.0 4.74 5.0 5.73 8.0 6.89

导入csv文件

第十四周作业 jupyter

涉及知识:

1、csv(逗号分隔值)是一种用来存储数据的纯文本文件,通常都是用于存放电子表格或数据的一种文件格式。一般用WORDPAD或记事本(NOTE),EXCEL打开。

2、%matplotlib inline 这是一个魔法函数 (magic function),是IPython中一种模仿命令行来访问magic函数的独有的形式

3、seaborn 是一个可以调整图表让你的图表更优美漂亮的库,知乎上有官方文档的中文翻译

4、read_csv() 读取csv文件

5、.head(10) 显示前10行数据, 如果没有参数则默认显示5行数据


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:  (hint: use statsmodels and look at the Statsmodels notebook)

第十四周作业 jupyter
涉及知识:

1、groupby 是pandas提供的一个能对数据集进行切片、切块、摘要等操作的函数

2、pandas.DataFrame.mean()求平均值

3、pandas.DataFrame.var()求方差

第十四周作业 jupyter

涉及知识:

.corr():返回列与列之间的相关系数


第十四周作业 jupyter

涉及知识:

scipy.stats.linregress : 只对计算两组测量值的最小二成回归进行优化,返回系数,截距,R2系数和标准差


    可以看出,四组数据x的平均值都是9.0,方差都是11.0; y的平均值都是7.5,方差都是4.12;x, y的相关系数都是0.81;四组数据的线性回归方程都近似 y = 0.5x + 3


Part 2

Using Seaborn, visualize all four datasets.

hint: use sns.FacetGrid combined with plt.scatter

第十四周作业 jupyter


相关文章: