import random
import numpy as np
import scipy as sp
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import statsmodels.api as sm
import statsmodels.formula.api as smf
sns.set_context("talk")
anascombe = pd.read_csv('anscombe.csv')
anascombe.head()
#part1
print(anascombe.groupby('dataset')['x'].mean())#x均值print(anascombe.groupby('dataset')['x'].var())#x方差
print(anascombe.groupby('dataset')['y'].mean())#y均值
print(anascombe.groupby('dataset')['y'].var())#y方差
print(anascombe.groupby('dataset').corr())#相关系数
x = sm.add_constant(x)
L = sm.OLS(x,y)
print(L.fit().summary())
#part2
g = sns.FacetGrid(anascombe, col='dataset', size=5)
g = g.map(plt.scatter, "x", "y")
plt.show()
plt.show()