Title: Linear Regression Using Scikit-Learn
Slug: linear_regression_using_scikit-learn
Summary: How to conduct linear 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 [6]:
# Load libraries
from sklearn.linear_model import LinearRegression
from sklearn.datasets import load_boston
import warnings
# Suppress Warning
warnings.filterwarnings(action="ignore", module="scipy", message="^internal gelsd")
In [7]:
# Load data
boston = load_boston()
X = boston.data
y = boston.target
In [8]:
# Create linear regression
regr = LinearRegression()
# Fit the linear regression
model = regr.fit(X, y)
In [9]:
# View the intercept
model.intercept_
Out[9]:
In [10]:
# View the feature coefficients
model.coef_
Out[10]: