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 Lasso
model = Lasso(alpha = 0.1)
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')
from sklearn.linear_model import SGDRegressor
model = SGDRegressor(penalty='l1')
model.fit(X, Y)
model.intercept_, model.coef_
X_new = np.linspace(0, 2, 100).reshape(-1, 1)
Y_predict = model.predict(X_new)
fig, ax = plt.subplots();
ax.scatter(X, Y);
ax.plot(X_new, Y_predict, 'r')