L

Data analytics · Capstone project

Two cities, one question: what is a home worth, and where is the price heading?

Master of Computer Information Technology, Data Analytics. A capstone on Beijing resale prices, rebuilt and carried over to Toronto.

See what the data says
2012
Median price per m², CNY20k100k+

Beijing, one hexagon per square kilometre or so, coloured by the median price per square metre of the homes sold there that year. Hover for the numbers.

About this project

My capstone asked whether a regression model could predict Beijing home prices. The first version scored an R² of 0.89. When I went back to it, I found out why: part of the answer was hiding in the question. So I rebuilt it, gave it a harder test, and then asked the same questions of Toronto.

Beijing · 296,577 homes after cleaning

Six years of a city heating up

A plain monthly average mixes up two things: prices going up, and different homes selling. So I compared like with like. A hedonic regression on size, rooms, age, floor, building type, district and distance to Tiananmen, with its own effect for every month, gives a quality-adjusted price index.

On that index, prices rose 236% from January 2012 to their peak in April 2017, then fell 15% by December.

The capstone model

An R² of 0.89 that was too good

The original model predicted a home's total price from a list of features, and one of them was the price per square metre. Total price is simply price per square metre times floor area, so the model was half reading the answer.

I reran the original R code to be sure: R² 0.89 on the training years and 0.80 on 2017. With the leak taken out, the same linear model falls to 0.15.

Capstone, with the leak

0.80R² on 2017 sales

9.3%median error per home

Tight, but only because unit price was one of the inputs.

The rebuild

Two honest tests

Valuation: hide a random 20% of sales and price them from everything else. Forecast: learn from 2011 to 2016 only, then price every home sold in 2017, the year the market turned.

Gradient-boosted trees with map coordinates did best: a median error of 4.6% on valuation, with 83% of homes within 10%. On the forecast, the error was 8.0%, and most of what was left was market timing: give the same model the month-by-month index and it drops to 5.1%.

  • +6.1%near a subway station
  • +9.3%with an elevator
  • +60.9%single-storey homes in the old hutongs
  • +4.6%hardcover renovation

Effects from the hedonic regression on price per square metre, holding size, rooms, age, district, distance and month equal.

Try it

Price a Beijing flat

The log-linear model, at the December 2017 market level. It is right to within about 12% for a typical home.

Estimated price

 CNY

 

Toronto · 158 neighbourhoods

The same questions, closer to home

Toronto doesn't publish sale-by-sale records the way Lianjia's listings exposed Beijing's, so I used what is public: 2021 census dwelling values and household incomes for all 158 neighbourhoods, the TTC's station locations, and the MLS Home Price Index for the GTA.

Income explains most of the map. Holding income equal, each kilometre from City Hall takes about 2.3% off a home's value. A subway station within a kilometre adds 2.0%, too small to tell apart from zero at this scale.

Average dwelling value, 2021 TTC subway station

GTA · MLS Home Price Index

Twenty years of the benchmark home

The benchmark is a typical home whose features stay fixed, the same idea as my Beijing index. Greater Toronto's benchmark price peaked at $854,200 in April 2017, again at $1,279,800 in February 2022, and stood at $925,900 in August 2026.

Side by side

Two markets, the same month

Put both indexes on the same base and they turn together. Beijing tightened down payments on second homes on March 17, 2017. Ontario announced its Fair Housing Plan, with a 15% tax on non-resident buyers, on April 20. Both markets peaked in April 2017.

Beijing had climbed much further, +236% against Greater Toronto's +88%, and fell a little harder: 15% by December, against 12.5%.

Distance

The centre pulls differently

In Beijing, price per square metre falls steadily with every kilometre from Tiananmen: by 12 km it is about half. Toronto's most valuable homes sit 2 to 10 km out, in midtown's detached-house neighbourhoods, while the condo-heavy core reads lower per home.

Beijing is price per square metre of homes sold in 2016 and 2017; Toronto is the 2021 census value per home. Each line is relative to its own innermost band.

  • 01

    Check what the model can see

    The capstone's best number came from a column that already held the answer. The first question about any model is what it was allowed to know.

  • 02

    Timing beats features

    Location and size price a home well. What a model can't learn from the past is a policy turn, and in 2017 both cities had one.

  • 03

    Transit pays where it's scarce

    A nearby subway station was worth about 6% in Beijing. Across Toronto's neighbourhoods, income swamps it.

Method and data

How it was built

Beijing. 318,851 resale transactions from Lianjia, published as a public dataset. Kept sales from 2011 to 2017 with valid building type, year built, area and price: 296,577 homes. Coordinates are Baidu BD-09, so distances are good to about half a kilometre.

Models. The original linear model, rerun in R; the same model without the leaked columns (unit price, community average price, days on market, followers); a log-linear hedonic model with district, distance and month effects; and LightGBM gradient-boosted trees with coordinates. Valuation uses a random 80/20 split; the forecast trains on 2011 to 2016 and tests on 2017.

Toronto and the GTA. City of Toronto Open Data: Neighbourhood Profiles (2021 Census), neighbourhood boundaries, and TTC schedules (GTFS) for station locations. CREA MLS® Home Price Index, monthly, not seasonally adjusted, for Greater Toronto, Mississauga, Oakville-Milton and Hamilton-Burlington.

Tools. R for the original capstone; Python, pandas and LightGBM for the rebuild; the charts on this page are hand-built SVG and canvas, with no chart library.