Paul's Python CoursePPC

Project 1 of 10, for Paul

House Price Predictor

Predict a house's price from its floor area, from 1,000 real sales: the best straight line found by formula, on foot by gradient descent, and by scikit-learn.

About 2 hours, in 19 steps.

Sign up free to open itLog in

Act 6 needs a free account, so your work is saved as you go. Act 1 is open to everyone.

The brief

  • PaulBefore I trust a model with anything real, I like to try it on data the whole world's already checked.
  • PaulI've got a thousand house sales from near Seattle, floor area against price, and I want the best line through them.
  • YahyaOkay, but best by what measure?
  • PaulThat's exactly the right question, and the whiteboard's free if you want to work it out.

king_county_houses.csv holds 1,000 real house sales from King County, Washington, between May 2014 and May 2015: the date, the price in dollars, the floor area in square metres, and some columns for later.

In house_prices.py, find the straight line that guesses a price from a floor area, price = w * area + b, three ways, and check they agree:

  1. By a formula.
  2. By walking downhill, a step at a time, from w = 0 and b = 0.
  3. With scikit-learn, the library most people use.

Print how far off the line's guesses typically are, in dollars. Then ask for a floor area and give the line's price for it, to the nearest thousand dollars. An area outside the sizes in the sales gets a warning instead of a price, and an answer that isn't a number gets told so.

What it prints
By formula: w = 3515.36, b = -140390
By descent: w = 3515.36, b = -140390
scikit-learn: w = 3515.36, b = -140390
Root mean squared error: $288,893
Floor area in square metres? 150
A house of 150 square metres: about $387,000

What you learn

What's in it

  1. A guess with dials
  2. Two houses, one line
  3. How wrong is it?
  4. Square, then average
  5. The best line
  6. The best line, by formula
  7. Walking downhill in fog
  8. Finding the bottom
  9. Two dials, two slopes
  10. How Paul would walk it
  11. Units change the hill
  12. Square metres or hundreds
  13. Fix Yahya's version
  14. The best line, on foot
  15. The library way
  16. One column is still a table
  17. The price of a house
  18. Ship it