An Automated Valuation Model (AVM) that predicts the resale price of Singapore HDB flats, built as an end-to-end, leakage-safe machine-learning pipeline.
TL;DR — A
HistGradientBoostingmodel in a fully leakage-safe scikit-learn pipeline, selected via time-series cross-validation against Random Forest and Ridge baselines. Evaluated once on a genuinely future hold-out period (Jan 2025 – Jun 2026): R² = 0.903, RMSE ≈ S$64.3k, MAE ≈ S$49.4k.
The model is positioned as an AVM for a bank's housing-loan desk (and, secondarily, for buyers checking whether a listing is fairly priced). It estimates a flat's resale price to inform (a) buyer advice and (b) the loan amount underwritten against the flat as collateral.
Cost of errors (defined up front, used to drive the final decision):
- Over-prediction → the bank over-lends against collateral that won't cover the loan on default — a direct credit-loss risk (the costlier error for a lender).
- Under-prediction → a conservative valuation; lost business, but not a solvency risk.
This asymmetry motivates a safety-margin analysis rather than a naive point estimate.
- Source: HDB resale flat transactions (public data, data.gov.sg).
- Size: 233,265 transactions spanning Jan 2017 → Jun 2026.
- Target:
resale_price(SGD) — a supervised regression task. - Features: town, flat type, flat model, storey range, floor area, lease commence date / remaining lease, street name, block.
The dataset (hdb_resale_flat_prices.csv, ~22 MB) is included in this repo so the notebook runs out of the box.
The notebook follows the CRISP-DM flow and is organised into five parts:
| Part | Focus |
|---|---|
| A | Advanced data prep & leakage-safe pipeline engineering — all learned transforms (impute, scale, one-hot, target-encode, log-target) live inside a single Pipeline; deterministic feature engineering is done pre-split and justified as such. |
| B | Champion model selection — Ridge vs. Random Forest vs. HistGradientBoosting under a shared pipeline and TimeSeriesSplit(5) cross-validation. |
| C | Controlled ablations & tuning — one variable changed per experiment, search capped at 24 fits, every experiment logged with an accept/reject conclusion. |
| D | Mechanical failure analysis — inspect the worst individual errors (not just aggregate metrics) and propose concrete fixes. |
| E | Business decision reasoning — translate the cost-of-errors structure into a safety-margin recommendation, then a single final hold-out evaluation. |
- Time-based split, not random. Prices rose ~54% across the window, so a random split would leak future price levels. The model trains on the past and is validated / tested on the future.
- Log-target modelling (
log(price)), confirmed empirically to beat the raw target. - No leakage.
price_per_sqm-style target-derived features are deliberately avoided; the test set is frozen and touched exactly once.
Data leakage — letting information from the test set (or the future) sneak into training — is the single easiest way to get an ML model that looks great in validation and fails in production. This project is built specifically to make leakage structurally impossible:
-
Every learned transformation lives inside one
sklearnPipeline. Imputation medians, theStandardScaler, one-hot categories, target-encoding statistics, and the log-target transform are allfiton the training folds only, then merelytransformthe validation/test data. Because cross-validation re-fits the whole pipeline on each fold, no statistic is ever computed over data the model is being scored on. -
Deterministic feature engineering is done before the split — and only that kind. Parsing
remaining_leasestrings into months, turningstorey_rangeinto a numeric level, and computing lease-decay are row-level operations that learn no parameters from other rows, so doing them up front cannot leak. Anything that does learn from the data (encoders, scalers, imputers) is deferred into the pipeline. That distinction is the whole game. -
The split is chronological, not random. With prices rising ~54% across the window, a random split would let the model "see" future price levels through neighbouring rows. Training is on the past; validation uses
TimeSeriesSplit; the model is only ever asked to predict forward in time. -
No target-derived features. Tempting fields like
price_per_sqmare excluded — they encode the answer. Only inputs knowable before a sale is priced are used. -
The test set is frozen and touched exactly once. The genuinely future period (Jan 2025 – Jun 2026) is set aside at the start and used for a single final evaluation after all model and hyperparameter decisions are locked — so the reported R² = 0.903 is an honest out-of-sample estimate, not a number the modelling was tuned against.
Champion: HistGradientBoostingRegressor — lower mean and lower fold-to-fold std RMSE than Random Forest and Ridge under time-series CV.
Tuned hyperparameters: max_leaf_nodes=31, max_iter=300, learning_rate=0.2.
Final single hold-out (Jan 2025 – Jun 2026), evaluated once:
| Metric | Value |
|---|---|
| R² | 0.903 |
| RMSE | ≈ S$64,269 |
| MAE | ≈ S$49,418 |
Failure mode: the largest errors are systematic under-predictions of the sparse million-dollar / rare-flat-type tail (worst case ≈ S$564k under). Proposed fixes include finer location features (planning area / postal sector) and better handling of the high-value tail.
Decision: because over-prediction is the costlier error for a lender, and the time-split model already errs conservative, the recommended safety margin depends on the use case — a judgement tied directly to the Part A cost structure.
.
├── hdb_resale_price_prediction.ipynb # main notebook (CRISP-DM, Parts A–E)
├── hdb_resale_flat_prices.csv # dataset (233,265 rows)
├── presentation.pdf # summary slide deck
├── results.png # results chart (shown above)
├── requirements.txt
├── LICENSE # MIT
└── README.md
Locally
python3 -m venv .venv && source .venv/bin/activate pip install -r requirements.txt jupyter lab # open hdb_resale_price_prediction.ipynb and run all
The notebook reads hdb_resale_flat_prices.csv from the working directory. A full run (tree-ensemble cross-validation on ~197k training rows) takes roughly 3–5 minutes.
Google Colab — upload the notebook and the CSV, then run all. The first cell installs category_encoders.
This is an academic group capstone (ICT6001, Week 1 group project — Group 7). Individual contributor names have been removed for privacy. Shared here as a portfolio piece; the underlying HDB dataset is publicly available from data.gov.sg.
Released under the MIT License.
