Skip to content

Instantly share code, notes, and snippets.

@ForteXX-2020
Created January 14, 2021 21:22
Show Gist options
  • Save ForteXX-2020/8017d7fc3941d8edd930b241f94f71ae to your computer and use it in GitHub Desktop.
Save ForteXX-2020/8017d7fc3941d8edd930b241f94f71ae to your computer and use it in GitHub Desktop.
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