import numpy as np
import matplotlib.pyplot as plt
from sklearn.metrics import  r2_score

np.random.seed(2)

pageSpeeds = np.random.normal(3.0,1.0,1000)
purchaseAmount = np.random.normal(50.0,10.0,1000)  / pageSpeeds

x = np.array(pageSpeeds)
y = np.array(purchaseAmount)

p4 = np.poly1d(np.polyfit(x,y,4))

xp = np.linspace(0,7,100)
plt.scatter(pageSpeeds,purchaseAmount)
plt.plot(xp,p4(xp),c='r')
print(plt.show())

#r-squared
r2 = r2_score(y, p4(x))
print(r2)


