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.
- 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.
- Pre-trained XGBoost model (
- 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.
.
├── app.py
├── model.bst
├── scaler.joblib
├── postal_data.json
├── tests/
├── Dockerfile
├── requirements.txt
└── README.mdIf you are setting this up from a Git repository:
git clone https://github.com/seehiong/hdb-price-predictor-app.git
cd hdb-price-predictor-appIf 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.
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.txtVerify that app.py, model.bst, scaler.joblib, and postal_data.json are in the current directory.
streamlit run app.pyThe application should now be accessible in your web browser, usually at http://localhost:8501.
python -m unittest discover -s tests -vThey 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.
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.
From the project's root directory (where the Dockerfile is located):
docker build -t hdb-price-predictor .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 binds0.0.0.0and exposes the unauthenticated Streamlit port to the whole network, bypassing Caddy. If loopback binding is not an option, block external:8501at the host firewall instead.
docker tag hdb-price-predictor <dockerhub-username>/hdb-price-predictor:latest
docker push <dockerhub-username>/hdb-price-predictor:latest- Model Training Data: Based on historical HDB Resale Flat Prices
- Data Last Updated (Reference in App): 30-06-2025
- 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.
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.