16

Model Diagnostics

Building models is a continuous art. As we start adding and removing variables from our models, we need a means to compare models with one another and a consistent way of measuring model performance. There are many ways we can compare models, and this chapter describes some of these methods.

16.1 Residuals

The residuals of a model compare what the model calculates and the actual values in the data. Let’s fit some models on a housing data set.

import pandas as pd
housing = pd.read_csv('data/housing_renamed.csv')

print(housing.head())
 neighborhood type units year_built sq_ft income \ 0 FINANCIAL R9-CONDOMINIUM 42 1920.0 36500 1332615 1 FINANCIAL R4-CONDOMINIUM 78 1985.0 126420 6633257 2 FINANCIAL ...

Get Pandas for Everyone: Python Data Analysis, 2nd Edition 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.