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
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.
Show the numbersHide the numbers
| Storeys | 2-room | 3-room | 4-room | 5-room | Executive |
|---|---|---|---|---|---|
| 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.
| Storeys | Median resale price | Sales | |
|---|---|---|---|
| 49–51 | $1,110,000 | 13 | |
| 46–48 | $1,051,400 | 36 | |
| 43–45 | $985,000 | 51 | |
| 40–42 | $912,500 | 182 | |
| 37–39 | $879,000 | 370 | |
| 34–36 | $861,444 | 418 | |
| 31–33 | $838,000 | 445 | |
| 28–30 | $808,500 | 844 | |
| 25–27 | $722,500 | 1,314 | |
| 22–24 | $642,400 | 2,188 | |
| 19–21 | $615,000 | 3,007 | |
| 16–18 | $530,000 | 7,125 | |
| 13–15 | $495,000 | 15,058 | |
| 10–12 | $458,000 | 29,411 | |
| 7–9 | $445,000 | 33,094 | |
| 4–6 | $430,000 | 36,297 | |
| 1–3 | $410,000 | 27,828 | |
| $0$250k$500k$750k$1M |
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
| Lease left | Median resale price | Sales | |
|---|---|---|---|
| 40–44 yrs | $295,000 | 337 | |
| 45–49 yrs | $282,000 | 2,938 | |
| 50–54 yrs | $355,000 | 7,336 | |
| 55–59 yrs | $358,000 | 13,888 | |
| 60–64 yrs | $400,000 | 21,895 | |
| 65–69 yrs | $415,000 | 20,505 | |
| 70–74 yrs | $530,000 | 12,798 | |
| 75–79 yrs | $485,000 | 19,917 | |
| 80–84 yrs | $450,000 | 15,519 | |
| 85–89 yrs | $550,000 | 6,643 | |
| 90–94 yrs | $520,450 | 30,040 | |
| 95–99 yrs | $485,000 | 5,865 | |
| $0$200k$400k$600k$800k |
By flat type
| Flat type | Median resale price | Sales | |
|---|---|---|---|
| 1 room | $190,000 | 61 | |
| 2 room | $253,000 | 2,538 | |
| 3 room | $323,000 | 37,076 | |
| 4 room | $452,000 | 66,188 | |
| 5 room | $550,000 | 39,728 | |
| Executive | $660,000 | 12,017 | |
| Multi-gen | $828,000 | 73 | |
| $0$200k$400k$600k$800k |
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.