Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- import numpy as np
- from matplotlib import style
- style.use('dark_background')
- X, Y = np.arange(1950, 2015, 5), [2558, 2782, 3043, 3350, 3712, 4089, 4451, 4855, 5287, 5700, 6090, 6474, 6864]
- x = np.linspace(1950, 2015, 5)
- X_Mean, Y_Mean = sum(X)/len(X), sum(Y)/len(Y)
- Sxx, Sxy = sum([(x - X_Mean)**2 for x in X]), sum([(X[i]-X_Mean)*(Y[i]-Y_Mean) for i in range(len(X))])
- B1 = Sxy / Sxx
- B0 = Y_Mean - B1*X_Mean
- y = B0 + B1*x
- def G(x): return B0 + B1*x
- for currentYear in X:
- plt.plot(currentYear, G(currentYear), 'ro', color="red")
- plt.title(f'G(X) = {int(B0)} + {int(B1)}x')
- plt.plot(x, y, color='red')
- plt.plot(X, Y, 'ro', color='white')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement