Created
September 30, 2018 15:22
-
-
Save animesh-agarwal/7a14800809251c590bc735b1817361cd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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