Title: Lasso Regression
Slug: lasso_regression
Summary: How to conduct lasso regression in scikit-learn for machine learning in Python.
Date: 2017-09-18 12:00
Category: Machine Learning
Tags: Linear Regression
Authors: Chris Albon
In [2]:
# Load library
from sklearn.linear_model import Lasso
from sklearn.datasets import load_boston
from sklearn.preprocessing import StandardScaler
In [3]:
# Load data
boston = load_boston()
X = boston.data
y = boston.target
In [4]:
# Standarize features
scaler = StandardScaler()
X_std = scaler.fit_transform(X)
In [5]:
# Create lasso regression with alpha value
regr = Lasso(alpha=0.5)
# Fit the linear regression
model = regr.fit(X_std, y)