text_plain_output_1.png image_output_1.png
from sklearn.linear_model import LinearRegression

import matplotlib.pyplot as plt

import numpy as np

import numpy as np # linear algebra

np.random.seed(0)
X = np.random.random(size=(20, 1))
y = 3 * X.squeeze() + 2 + np.random.randn(20)

model = LinearRegression()
model.fit(X, y)
X_fit = np.linspace(0, 1, 100)[:, np.newaxis]
y_fit = model.predict(X_fit)
y_model = 3 * X_fit.ravel() + 2 + np.random.randn(100)
plt.plot(X, y, 'o')
plt.plot(X_fit, y_fit)
plt.plot(X_fit, y_model)