In [4]:
from scipy.stats import norm
import matplotlib.pyplot as plt
import numpy as np
page_speeds = np.random.normal(3.0,1.0,1000)
purchase_amount = 100 - (page_speeds + np.random.normal(0,0.1, 1000))*3
plt.scatter(page_speeds,purchase_amount)
Out[4]:
In [5]:
from scipy import stats
slope, intercept, r_value, p_value, std_err = stats.linregress(page_speeds,purchase_amount)
In [6]:
r_value**2
Out[6]:
In [7]:
import matplotlib.pyplot as plt
def predict(x):
return slope * x + intercept
fit_line = predict(page_speeds)
plt.scatter(page_speeds,purchase_amount)
plt.plot(page_speeds,fit_line, c='r')
plt.show()