Building machine learning models
One of the most simple machine learning models we can construct to make a forecast of future behaviors is linear regression, which reduces the residual sum of squares between the targets observed in the dataset and the targets anticipated by the linear approximation, fitting a linear model using coefficients.
This is simply ordinary least squares or non-negative least squares wrapped in a predictor object from the implementation perspective.
We can implement this really simply by using the LinearRegression
class in Sklearn:
from sklearn.linear_model import LinearRegression from sklearn.datasets import load_diabetes data_reg = load_diabetes() x,y = data_reg['data'],data_reg['target'] reg = LinearRegression().fit(x, y) reg.score(x, y)
Figure 2.24: Model regression score
The preceding code will fit a linear regression model to our data and print the score of our data.
We can also print the coefficients...