import numpy as np
X = 2*np.random.rand(100, 1)
Y = 4 + 3 * X + np.random.randn(100, 1)
from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.fit(X, Y)
model.intercept_, model.coef_
X_new = np.linspace(0, 2, 100).reshape(-1, 1)
Y_predict = model.predict(X_new)
import matplotlib.pyplot as plt
fig, ax = plt.subplots();
ax.scatter(X, Y);
ax.plot(X_new, Y_predict, 'r')