Skip to content

About

A Streamlit web app that predicts Singapore HDB resale flat prices using a pre-trained XGBoost model. Includes an interactive transaction map, light/dark theme toggle, and Docker support for easy deployment.

Resources

Stars

8 stars

Watchers

0 watching

Forks

 
 

Latest commit

 

History

21 Commits

Folders and files

Repository files navigation

🏠 HDB Resale Price Predictor App

A Streamlit web application that predicts Singapore HDB resale flat prices. This app loads an XGBoost model and necessary data files (scaler, postal code data) directly from its local directory and displays an interactive transaction map hosted externally.

✨ Features

  • Interactive UI: User-friendly input for property details via Streamlit.
  • Local Model & Data:
    • Pre-trained XGBoost model (model.bst) loaded locally.
    • Data scaler (scaler.joblib) applied for consistent feature scaling.
    • Postal code data (postal_data.json) for location-based information.
  • Integrated Transaction Map:
    • Displays HDB resale transactions on an interactive map via an iframe to an externally hosted HTML file.
    • Clickable markers show recent transaction details for each block.
  • Responsive Design: Includes CSS adjustments for better viewing on mobile devices.
  • Theme Toggle: Light and Dark mode options.
  • Dockerized: Ready for containerization.

📁 Project Structure

.
├── app.py
├── model.bst
├── scaler.joblib
├── postal_data.json
├── tests/
├── Dockerfile
├── requirements.txt
└── README.md

🚀 Running Locally

1. Clone the repository

If you are setting this up from a Git repository:

git clone https://github.com/seehiong/hdb-price-predictor-app.git
cd hdb-price-predictor-app

If you have the files directly, ensure all files listed in the "Project Structure" (excluding the map HTML itself from the local app directory) are in your working directory.

2. Install dependencies

It's recommended to use a virtual environment:

python -m venv venv
source venv/bin/activate  # On Windows use `venv\Scripts\activate`

Then install the required packages:

pip install -r requirements.txt

3. Ensure local required files are present

Verify that app.py, model.bst, scaler.joblib, and postal_data.json are in the current directory.

4. Run the Streamlit app

streamlit run app.py

The application should now be accessible in your web browser, usually at http://localhost:8501.

5. Run the tests

python -m unittest discover -s tests -v

They drive the real app with Streamlit's AppTest (no extra packages) and check the price it shows for a known June 2025 resale against what it actually sold for.

🐳 Docker Instructions

The image is a small multi-stage build: Python deps go into an isolated venv in the builder stage, and the runtime stage is a slim, non-root image with only the app, its model/data files, and the OpenMP runtime xgboost needs. The base image is pinned by digest so rebuilds are reproducible. A HEALTHCHECK polls Streamlit's /_stcore/health endpoint.

1. Build the Docker image

From the project's root directory (where the Dockerfile is located):

docker build -t hdb-price-predictor .

2. Run the Docker container (shared host behind Caddy)

This app is meant to sit on a single shared Docker host with a Caddy reverse proxy terminating TLS as the only public front door. Streamlit ships no auth of its own, so the published port is bound to loopback — Caddy proxies to it locally on the same host, and nothing external can reach :8501 directly:

docker run -d --name hdb --restart unless-stopped \
  -p 127.0.0.1:8501:8501 hdb-price-predictor

--server.address=0.0.0.0 stays set inside the container (Docker port mapping requires it); the network restriction belongs on the host publish, not the app bind. Caddy then routes a hostname to it, e.g.:

hdb.example.com {
    reverse_proxy 127.0.0.1:8501
}

For a purely local check (no proxy), -p 127.0.0.1:8501:8501 still serves the app at http://localhost:8501 on your own machine.

⚠️ Do not publish with a bare -p 8501:8501: that binds 0.0.0.0 and exposes the unauthenticated Streamlit port to the whole network, bypassing Caddy. If loopback binding is not an option, block external :8501 at the host firewall instead.

(Optional) Tag and Push to a Container Registry (e.g. Docker Hub)

docker tag hdb-price-predictor <dockerhub-username>/hdb-price-predictor:latest
docker push <dockerhub-username>/hdb-price-predictor:latest

📈 Data

  • Model Training Data: Based on historical HDB Resale Flat Prices
  • Data Last Updated (Reference in App): 30-06-2025

🛠 Built With

  • Streamlit: For the web application framework.
  • XGBoost: For the prediction model.
  • scikit-learn: For data scaling (StandardScaler).
  • Joblib: For saving/loading the scaler.
  • Pandas & GeoPandas: Used in the notebook/script that generates the map data.
  • Folium: For generating the interactive HTML map (which is then hosted externally).
  • Docker: For containerization.

📝 Notes

The prediction model (model.bst) and scaler (scaler.joblib) must be compatible with the feature engineering implemented in app.py: change all three together. XGBoost silently accepts a feature vector of the wrong length, so the app refuses to start if the model's feature count differs from FEATURE_NAMES, or if the scaler's recorded feature names are missing or differ from it (fit the scaler on a DataFrame with those columns). model.bst stores no feature names, so a reordered list of the same length passes both checks: the known-transaction test is what catches that. The hdb_resale_price_map_clickable.html file is generated by a separate process (e.g., a Jupyter Notebook using Folium) and hosted externally (e.g., on GitHub Pages). The URL to this live map must be correctly configured in app.py.

📄 Related Blog Post

👉 Deploy KServe on OKE

About

A Streamlit web app that predicts Singapore HDB resale flat prices using a pre-trained XGBoost model. Includes an interactive transaction map, light/dark theme toggle, and Docker support for easy deployment.

Resources

Stars

8 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages