# Anscombe's quartet

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

```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 = sns.load_dataset("anscombe")
print(anascombe)```

Part1

```print("\nMean:")
print(anascombe.groupby("dataset").mean())
print("\nVariance:")
print(anascombe.groupby("dataset").var())```

```print("\nCorrelation coefficient:")
print(anascombe.groupby("dataset").x.corr(anascombe.y))```

或

```X = []
Y = []
coefficients = []
for i in range(0, 4):
X.append(anascombe.x[i*11:i*11+11].values)
Y.append(anascombe.y[i*11:i*11+11].values)
coefficients.append(sp.stats.pearsonr(X[i], Y[i])[0])
print(coefficients[i])```

```for i in range(0,4):
x = X[i]
model = sm.OLS(Y[i], x)
results = model.fit()
print("\nThe linear regression " + str(i+1))
print(" y = "+str(results.params[0])+"+"+str(results.params[1])+"x")```

Part2

```sns.lmplot(x="x", y="y", col="dataset", hue="dataset", data=anascombe,
col_wrap=2, ci=None, palette="muted", size=4,
scatter_kws={"s": 80, "alpha": 1})
plt.show()```