AI Hints
Home›Machine Learning Tutorial›Workflow and Setup
Machine Learning · Lesson 6 of 85

Meet the Housing Data

Twenty thousand real homes.

⏱ 2 min read▶ Video at 13:07🎓 Free
Watch this lesson in the Machine Learning courseWatch on YouTube ↗Full Machine Learning course

HomeWorth has just bought a dataset. It covers more than twenty thousand districts in California, taken from a real census. It will be your training ground for the next few hours. Before any model touches it, a professional does one thing first. They look at it.

Meet the Housing Data
From the video: Meet the Housing Data
  • Real census data
  • Over twenty thousand districts
  • First rule: look at the data

First look at the data

We load the data as a table, called a data frame. Shape tells us the size, twenty thousand six hundred and forty rows, and nine columns. The columns list tells us what each one means. And head shows the first few rows. Each row is a district. Med inc is the median income. House age, and average rooms, describe the homes. Latitude and longitude tell us where it is. And the final column, med house val, is the price, in units of a hundred thousand dollars. That is the number we want to predict.

look.pypython
from sklearn.datasets import fetch_california_housing

housing = fetch_california_housing(as_frame=True)
df = housing.frame

print(df.shape)
print(df.columns.tolist())
print(df.head(3).round(2).to_string())
Output
(20640, 9)
['MedInc', 'HouseAge', 'AveRooms', 'AveBedrms', 'Population', 'AveOccup', 'Latitude', 'Longitude', 'MedHouseVal']
   MedInc  HouseAge  AveRooms  AveBedrms  Population  AveOccup  Latitude  Longitude  MedHouseVal
0    8.33      41.0      6.98       1.02       322.0      2.56     37.88    -122.23         4.53
1    8.30      21.0      6.24       0.97      2401.0      2.11     37.86    -122.22         3.58
2    7.26      52.0      8.29       1.07       496.0      2.80     37.85    -122.24         3.52

Features and target

Two words will now appear in every lesson. Features are the inputs, the facts we know about each example. By tradition, we call them capital X. The target is the output, the thing we want to predict, called small y. In our data, income, house age, and location are features, and the price is the target. Each row is one example. Fit learns the link from X to y.

keyvalue
Features (X)income, age, rooms, location
Target (y)median house value
Exampleone row, one district
Modelthe link from X to y

Summary

You have met the data, and learned the three words of the trade. Features, target, and example. But this data looks too clean. Is it hiding something? Next, we learn the two libraries that let us find out.

Key takeaways
  • Always look at the data first
  • X holds features, y holds the target
  • Each row is one example
Next up: NumPy in Ten Minutes — fast maths on whole arrays