Skip to content

Instantly share code, notes, and snippets.

@drmingle
Created April 30, 2018 23:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drmingle/5d67775fea0ee0ccfd39dcd7cae0f195 to your computer and use it in GitHub Desktop.
Save drmingle/5d67775fea0ee0ccfd39dcd7cae0f195 to your computer and use it in GitHub Desktop.
title author date
Loading scikit-learn's Boston Housing Dataset
Damian Mingle
04/30/2018

Preliminaries

# Load library
from sklearn import datasets

Load Boston Housing Dataset

The Boston housing dataset contains 506 observations on housing prices for Boston suburbs and has 15 features. The medv variable is the target variable.

Data description

crim

per capita crime rate by town.

zn

proportion of residential land zoned for lots over 25,000 sq.ft.

indus

proportion of non-retail business acres per town.

chas

Charles River dummy variable (= 1 if tract bounds river; 0 otherwise).

nox

nitrogen oxides concentration (parts per 10 million).

rm

average number of rooms per dwelling.

age

proportion of owner-occupied units built prior to 1940.

dis

weighted mean of distances to five Boston employment centres.

rad

index of accessibility to radial highways.

tax

full-value property-tax rate per $10,000.

ptratio

pupil-teacher ratio by town.

black

1000(Bk - 0.63)^2 where Bk is the proportion of blacks by town.

lstat

lower status of the population (percent).

medv

median value of owner-occupied homes in $1000s.

# Load dataset
boston = datasets.load_boston()

# Create feature matrix
features = boston.data

# Create target vector
target = boston.target

# View the feature values for the first observation
features[0]
array([6.320e-03, 1.800e+01, 2.310e+00, 0.000e+00, 5.380e-01, 6.575e+00,
       6.520e+01, 4.090e+00, 1.000e+00, 2.960e+02, 1.530e+01, 3.969e+02,
       4.980e+00])

Source

Harrison, D. and Rubinfeld, D.L. (1978) Hedonic prices and the demand for clean air. J. Environ. Economics and Management 5, 81–102.

Belsley D.A., Kuh, E. and Welsch, R.E. (1980) Regression Diagnostics. Identifying Influential Data and Sources of Collinearity. New York: Wiley.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment