Skip to content
Housing Price Regression Model Shootout
Housing Price Prediction Models
This nootbook contains a shootout between regression type models, attempting to predict housing prices based on a number of variables. Some of these variables include: Zoning, Lot Size, Pools, Bedrooms, etc.
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import os as os
from sklearn.metrics import mean_squared_error
from sklearn.metrics import mean_absolute_error
from sklearn.metrics import r2_score
from sklearn.model_selection import GridSearchCV
from numpy import arange
%matplotlib inline
import sys
pd.set_option('display.max_colwidth', 1000)
pd.set_option('display.max_rows', 1000)Read in AmesHousing.csv into a Dataframe Called Ames
#import data
Ames = pd.read_csv("AmesHousing.csv", sep=",", engine='python')
Ames.shapeExplore the Dimensions and Structures of the Dataframe
Ames.head()#Check data types
Ames.dtypes.head()#Remove the ID fields
Ames=Ames.drop(['Order', 'PID'],axis=1)
Ames.head()# designate target variable name and move to front of dataframe
targetName = 'SalePrice'
targetSeries = Ames[targetName]
del Ames[targetName]
Ames.insert(0, targetName, targetSeries)
Ames.head()Ames.describe()Replace missing number values with variable mean
Replace missing object values with 'NONE'
Ames.isna().any().head()#Fill NaN values of number variables with mean
for col in Ames.columns[1:]:
dType = Ames[col].dtype
if dType == float or dType == int:
Ames[col].fillna(value=Ames[col].mean(), inplace=True)
else:
Ames[col].fillna(value='NONE', inplace=True)Ames.isna().any().head()
#Success!