Evaluating the linear regression model
In this recipe, we'll look at how well our regression fits the underlying data. We fitted a regression in the last recipe, but didn't pay much attention to how well we actually did it. The first question after we fitted 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...
- Start within IPython with several imports, including
numpy
,pandas
, andmatplotlib
for visualization:
import numpy as np import pandas as pd import matplotlib.pyplot as plt %matplotlib inline
- It is worth looking at a Q-Q plot. We'll use
scipy
here because it has a built-in probability plot:
from scipy.stats import probplot f = plt.figure(figsize=(7, 5)) ax = f.add_subplot(111) tuple_out = probplot(boston.target - predictions_cv...