题目:https://nbviewer.jupyter.org/github/schmit/cme193-ipython-notebooks-lecture/blob/master/Exercises.ipynb
前置:
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")
ana = pd.read_csv('C:/Users/hasee/Desktop/anscombe.csv')
Part1:
#Part 1
#
x = ana['x']
y = ana['y']
mean1 = np.average(x)
var1 = np.var(x)
mean1 = np.average(y)
var1 = np.var(y)
#
coe = np.corrcoef(x,y)
#
X = sm.add_constant(x)
res = sm.OLS(y, X)
result = res.fit()
result.params
结果为:
Part2:
sns.FacetGrid(ana, 'dataset').map(plt.scatter, 'x', 'y')
plt.show()
结果为: