Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- def prodScal(X,Y):
- n = len(X)
- if n != len(Y) : return
- return sum([X[i]*Y[i] for i in range(n)])/n
- def esperance(X):
- return sum(X)/len(X)
- def covariance(X,Y):
- return prodScal(X,Y)-esperance(X)*esperance(Y)
- def variance(X):
- return sum([x**2 for x in X])/len(X) - esperance(X)**2
- def regLin(X,Y):
- n = len(X)
- if n != len(Y) : return
- lbda = covariance(X,Y)/variance(X)
- mu = esperance(Y)-lbda*esperance(X)
- return lbda,mu
- def graph(X,Y):
- plt.scatter(X,Y)
- lbda,mu = regLin(X,Y)
- plt.plot(X, [lbda*X[i]+mu for i in range(len(X))])
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement