Barnabas SngProjects

Singapore HDB resale price predictor

My first machine-learning project, from 2023: a gradient-boosted model that estimates an HDB flat’s resale price from its features, built on a dataset of 157,681 resale transactions.

Data
data.gov.sg resale transactions, January 2017 to July 2023
Model
XGBoost regressor, up to 1,000 trees with early stopping
Result
Test RMSE of about $48,080, against a median price of $455,000
Code
Jupyter notebook on GitHub

Higher floors, higher prices

The median resale price for each storey band and flat type, from January 2017 to July 2023. Hover over or tap a point to read it; the table under the chart has every value.

Each point rests on at least 10 sales; bands with fewer sales of a type are left out, which is why some lines stop early and storeys 49 to 51 have no points.
Show the numbersHide the numbers
Median HDB resale price by storey band and flat type, January 2017 to July 2023. A dash marks a band with fewer than 10 sales of that type.
Storeys2-room3-room4-room5-roomExecutive
1–3$240,000$300,000$410,000$500,000$640,000
4–6$241,000$315,000$433,000$525,000$659,499
7–9$250,000$323,000$450,000$540,000$668,000
10–12$258,000$330,000$457,000$550,000$680,000
13–15$262,000$360,000$487,888$564,000$650,000
16–18$273,000$398,000$518,000$610,000$675,000
19–21$280,000$435,000$610,000$690,000$800,000
22–24$310,000$475,000$642,000$715,000$996,000
25–27$304,500$548,000$735,000$830,000–
28–30–$588,000$800,000$910,000–
31–33–$620,000$830,000$1,012,500–
34–36–$608,500$850,000$1,053,000–
37–39–$612,500$860,000$1,039,000–
40–42–$659,000$883,000$1,138,888–
43–45––$985,000––
46–48––$1,030,000$1,210,000–

Median price rises with storey band

Median resale price by storey band across all 157,681 transactions. Prices climb from $410,000 on storeys 1 to 3 to $1,110,000 on storeys 49 to 51, but the top bands rest on very few sales.

Median HDB resale price and number of sales by storey band, January 2017 to July 2023
StoreysMedian resale priceSales
49–51$1,110,00013
46–48$1,051,40036
43–45$985,00051
40–42$912,500182
37–39$879,000370
34–36$861,444418
31–33$838,000445
28–30$808,500844
25–27$722,5001,314
22–24$642,4002,188
19–21$615,0003,007
16–18$530,0007,125
13–15$495,00015,058
10–12$458,00029,411
7–9$445,00033,094
4–6$430,00036,297
1–3$410,00027,828
Median price Fainter bars rest on fewer sales Median of all sales, $455,000

Method

Data. Resale transactions from data.gov.sg, January 2017 to July 2023, merged with HDB’s property information by block and street. That gives 157,681 transactions, each with the flat’s details and the block’s amenities.

Features. For each sale:

  • Town, flat type and flat model, one-hot encoded
  • Storey range, encoded as an ordinal so that higher bands rank higher
  • Floor area
  • Remaining lease, converted from years and months into a number of years
  • Amenity flags for the block: commercial units, a market or hawker centre, a multi-storey car park, a precinct pavilion and miscellaneous

Training. The data was split at random, 70/15/15, into training, validation and test sets, rather than by date. Scaling used a StandardScaler fit on the training split only, so the scaler never saw validation or test data. The model is an XGBoost regressor with up to 1,000 trees, stopped early once the validation error stopped improving.

Built with Python, pandas, XGBoost, scikit-learn, matplotlib and seaborn, in a Jupyter notebook.

Results

Test RMSE
$48,080approximate, on the held-out test set
Median resale price
$455,000across the whole dataset
Floor area and price
0.61correlation coefficient

Counted by how often each feature is used in a split, XGBoost ranked remaining lease, floor area and storey range highest. Split counts favour numeric features over one-hot columns, so this ranks how often a feature is used, not how much it moves the price.

Price by lease and flat type

Two more views of the same data, on one price scale, each with the number of sales behind every median. The dashed line is the median of all sales, $455,000.

By remaining lease

Median HDB resale price and number of sales by remaining lease, in five-year bands
Lease leftMedian resale priceSales
40–44 yrs$295,000337
45–49 yrs$282,0002,938
50–54 yrs$355,0007,336
55–59 yrs$358,00013,888
60–64 yrs$400,00021,895
65–69 yrs$415,00020,505
70–74 yrs$530,00012,798
75–79 yrs$485,00019,917
80–84 yrs$450,00015,519
85–89 yrs$550,0006,643
90–94 yrs$520,45030,040
95–99 yrs$485,0005,865
The raw medians do not rise steadily with remaining lease; the model weighs lease alongside location, flat type and size rather than on its own.

By flat type

Median HDB resale price and number of sales by flat type
Flat typeMedian resale priceSales
1 room$190,00061
2 room$253,0002,538
3 room$323,00037,076
4 room$452,00066,188
5 room$550,00039,728
Executive$660,00012,017
Multi-gen$828,00073
From $190,000 for a 1-room flat to $828,000 for a multi-generation flat. Both of those types are rare, with 61 and 73 sales.

What I would do differently

  • Replace the one-hot towns, which are a crude stand-in for location, with the distance to the CBD computed from each block’s latitude and longitude.
  • Build a reusable pipeline. The notebook transforms the data step by step, so pricing a new flat means repeating each transformation by hand.

To talk about this project, email barnabassng10@gmail.com.