Evaluating the linear regression model
In this recipe, we'll look at how well our regression fits the underlying data. We fit a regression in the last recipe, but didn't pay much attention to how well we actually did it. The first question after we fit the model was clearly "How well does the model fit?" In this recipe, we'll examine this question.
Getting ready
Let's use the lr
object and boston
dataset—reach back into your code from the Fitting a line through data recipe. The lr
object will have a lot of useful methods now that the model has been fit.
How to do it...
There are some very simple metrics and plots we'll want to look at as well. Let's take another look at the residual plot from the last chapter:
>>> import matplotlib.pyplot as plt
Get scikit-learn : Machine Learning Simplified now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.