Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
0004_OLSregression
from pylab import plt
import numpy as np
def f(x):
return 3 * x ** 3 - 4 * x ** 2
x = np.linspace(-2, 4, 25)
y = f(x)
plt.figure(figsize=(10, 6))
plt.plot(x, y, 'ro');
a, b = np.polyfit(x, y, 1)
y_hat = a*x + b
plt.plot(x, y_hat, 'b-');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment