Now, we get to do some modeling! It's best to start simple; therefore, we'll look at linear regression first. Linear regression is the first, and therefore, probably the most fundamental model—a straight line through data.
The boston
dataset is perfect to play around with regression. The boston
dataset has the median home price of several areas in Boston. It also has other factors that might impact housing prices, for example, crime rate.
First, import the datasets
model, then we can load the dataset:
>>> from sklearn import datasets >>> boston = datasets.load_boston()
Actually, using linear regression in scikit-learn is quite simple. The API for linear regression is basically the same API you're now familiar with from the previous chapter.
First, import the LinearRegression
object and create an object:
>>> from sklearn.linear_model import LinearRegression >>> lr = LinearRegression()
Now, it's as easy...