October 2017
Beginner to intermediate
270 pages
7h
English
Now, we will define a function implementing the correlation method to find the parameters for our regression:
def correlation_fit(x, y):
beta = correlation(x, y) * np.std(y, ddof=1) / np.std(x,ddof=1)
alpha = np.mean(y) - beta * np.mean(x)
return alpha, beta
Let’s then run the fitting function and print the guessed parameters:
alpha, beta = correlation_fit(X, Y) print(alpha) print(beta)1.08355803285 2.22994049512
Let’s now graph the regressed line with the data in order to intuitively show the appropriateness of the solution:
plt.scatter(X,Y)
xr=np.arange(0,3.5)
plt.plot(xr,(xr*beta)+alpha)
This is the final plot we will get with our recently calculated slope and intercept:
Read now
Unlock full access