Skip to content

Instantly share code, notes, and snippets.

@animesh-agarwal
Created September 30, 2018 15:22
Show Gist options
  • Save animesh-agarwal/7a14800809251c590bc735b1817361cd to your computer and use it in GitHub Desktop.
Save animesh-agarwal/7a14800809251c590bc735b1817361cd to your computer and use it in GitHub Desktop.
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
np.random.seed(0)
x = 2 - 3 * np.random.normal(0, 1, 20)
y = x - 2 * (x ** 2) + 0.5 * (x ** 3) + np.random.normal(-3, 3, 20)
# transforming the data to include another axis
x = x[:, np.newaxis]
y = y[:, np.newaxis]
model = LinearRegression()
model.fit(x, y)
y_pred = model.predict(x)
plt.scatter(x, y, s=10)
plt.plot(x, y_pred, color='r')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment