GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - moonsocks19/hdb-resale-price-prediction: Automated Valuation Model for Singapore HDB resale flat prices — a leakage-safe scikit-learn pipeline (CRISP-DM). HistGradientBoosting champion; R² = 0.90 on a genuinely future hold-out.

BranchesTags
Open more actions menu

Latest commit

 

History

2 Commits
2 Commits

Folders and files

NameName
Last commit message
Last commit date
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
hdb_resale_flat_prices.csv
hdb_resale_flat_prices.csv
 
 
hdb_resale_price_prediction.ipynb
hdb_resale_price_prediction.ipynb
 
 
presentation.pdf
presentation.pdf
 
 
requirements.txt
requirements.txt
 
 
results.png
results.png
 
 

Repository files navigation

HDB Resale Flat Price Prediction

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.

Python scikit-learn Methodology License Status

TL;DR — A HistGradientBoosting model 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.


Problem framing

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.

Dataset

  • 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.

Methodology (CRISP-DM)

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.

Key design choices

  • 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.

How the pipeline avoids leakage

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:

  1. Every learned transformation lives inside one sklearn Pipeline. Imputation medians, the StandardScaler, one-hot categories, target-encoding statistics, and the log-target transform are all fit on the training folds only, then merely transform the 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.

  2. Deterministic feature engineering is done before the split — and only that kind. Parsing remaining_lease strings into months, turning storey_range into 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.

  3. 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.

  4. No target-derived features. Tempting fields like price_per_sqm are excluded — they encode the answer. Only inputs knowable before a sale is priced are used.

  5. 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.

Results

Results — champion tuning and safety-margin tradeoff

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.

Repository 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

How to run

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.

Notes

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.

License

Released under the MIT License.

About

Automated Valuation Model for Singapore HDB resale flat prices — a leakage-safe scikit-learn pipeline (CRISP-DM). HistGradientBoosting champion; R² = 0.90 on a genuinely future hold-out.

Topics

crisp-dmdata-sciencegradient-boostinghdbjupyter-notebookmachine-learningreal-estateregressionscikit-learnsingapore

Resources

Readme
MIT license
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.