How francesshenaiclass/tpe-real-estate-ai works
1. Repository purpose
- This is a file-based, end-to-end Taipei real-estate analytics repo: it collects raw housing and geography data, cleans and merges it, trains price models, and serves prediction/recommendation/trend APIs plus a few HTML dashboards.
2. Main architectural boundary
- The clearest “production-like” path is under project/ and train/.
- Everything else (kevin/, frances/, 永慶房屋/, 實價登錄最終版/, final/) is part of the broader data-prep ecosystem: crawlers, cleaning scripts, intermediate CSV/JSON outputs, and earlier pipeline variants.
3. Data ingestion layer
- Raw market data comes from multiple district-based crawler outputs and transaction datasets, stored mostly as CSVs/JSONs.
- The repo contains many per-district files for Taipei’s 12 districts (中山區, 中正區, 信義區, etc.), indicating the pipeline is partitioned geographically at ingestion time.
- Sources include:
- current listings / asking prices
- real transaction / “實價登錄” records
- MRT station coordinates / exits
- district population, age, and income data
4. Cleaning and normalization layer
- Scripts such as data_cleaning*.py, clean_v1.py, district_population.py, mrt.py, history_merge.py, prediction_merge.py, and various merge scripts normalize raw crawler outputs into consistent tabular features.
- This layer appears to resolve:
- district naming and encoding
- MRT proximity / station clustering
- coordinate-based features
- demographic enrichment
- district-level aggregation and deduplication
5. Intermediate datasets
- The repo is strongly file-driven rather than database-driven.
- Important merged outputs include datasets such as:
- house_prices_taipei2.csv
- house_prediction_data.csv
- final_taipei_real_price.csv
- merged_cleaned.csv
- api_merge_all_data.csv
- district-specific cleaned CSVs
- These files act as the interface between ETL and model training.
6. Model training subsystem
- train/train_v3.py is the main training entry point in the consolidated flow.
- The system trains six LightGBM quantile models:
- three for real transaction prices
- three for listing prices
- Each family predicts low / mid / high price bands, corresponding to P10 / P50 / P90.
- Trained model artifacts are stored as .pkl files in train/models_v3_mrt_cluster/ and mirrored in project/models/.
7. Feature and encoding boundary
- The model boundary depends on encoded geography and transport features:
- district encoding
- MRT cluster encoding
- exact latitude/longitude
- distance to MRT
- coordinate interaction terms
- building attributes and transaction month
- Supporting lookup maps live in JSON files such as district_map.json, mrt_cluster_map.json, and mrt_stations.json, so inference depends on these static reference assets.
8. Serving layer
- project/main.py is the FastAPI application entry point.
- The API surface is split into three functional modules:
- predict_v3.py for price prediction
- recommender.py for recommendation logic
- market_trends.py for market trend analytics
- The API loads trained model files from project/models/ and reads static geography maps from project/static/.
9. Presentation layer
- project/templates/ contains HTML pages for the main UI:
- index.html
- page_predict.html
- page_recommend.html
- page_trends.html
- project/static/ provides the map and station metadata needed by the front end to render districts, MRT coverage, and cluster information.
- There are also standalone demo/dashboard entry points in taipeihouseapi/ and taipei-real-estate-quant-engine/.
10. Operational flow
- The runtime flow is:
- crawl raw housing/geographic data
- clean and merge into modeling tables
- train LightGBM quantile models
- store .pkl model artifacts plus JSON lookup maps
- serve predictions and analytics through FastAPI
- render results in template-based pages
11. Repo organization insight
- The repo looks like a merged workspace from multiple contributors and iterations, not a single tidy app.
- For architecture diagrams, treat project/ + train/ as the core system, and the other top-level folders as supporting ETL/crawler branches and legacy or exploratory implementations.
Main entry points: main.py API entry · district_map.json Static maps · process.py Real-price merge · predict_v3.py Predict API
Components 19
Data prep
Crawler, cleaning, and merge pipelines that build modeling tables.
- Raw crawlers · District-based housing and listing collection across multiple contributor branches.
kevin/crawler.py - JSON to CSV · Converts crawler outputs into tabular district files.
kevin/json_to_csv.py - Clean v1 · Early normalization and cleanup for housing data.
kevin/clean_v1.py - Merge pipeline · Combines district outputs into merged datasets for downstream use.
kevin/merge.py - API merge · Merges district-level API inputs into a consolidated dataset.
frances/api/api_merge_all.py - District cleaning · Cleans and standardizes district and age/population inputs.
永慶房屋/data_cleaning.py - Geo enrich · Adds MRT and demographic features such as station coordinates and population.
final/mrt.py - Real-price merge · Builds the consolidated real-estate training table.
實價登錄最終版/process.py
Core app
Training artifacts and FastAPI serving path used in the main flow.
- Training entry · Main consolidated LightGBM training entry point.
train/train_v3.py - Model artifacts · Stored LightGBM quantile models for real and listing price bands.
train/models_v3_mrt_cluster/lgbm_real_mid.pkl - API entry · Main FastAPI application that wires routes and serves the app.
project/main.py - Predict API · Price prediction endpoints backed by trained models.
project/api/predict_v3.py - Recommend API · Property recommendation logic and ranking endpoints.
project/api/recommender.py - Trends API · Market trend analytics and summary endpoints.
project/api/market_trends.py - Static maps · District, MRT cluster, and station lookup maps used during inference and UI rendering.
project/static/district_map.json - HTML views · Template pages for prediction, recommendation, and trend dashboards.
project/templates/index.html
Legacy demos
Alternative or earlier UI/API implementations and dashboards.
- Legacy API · Earlier API/dashboard implementation for house-price exploration.
taipeihouseapi/api.py - Quant dashboard · Standalone quant-engine demo UI and entry point.
taipei-real-estate-quant-engine/main.py - Final price app · Alternative real-price dashboard and API implementation.
永慶房屋/main.py
Connections 21
- Raw crawlers → JSON to CSV: raw output · Crawler outputs are converted into CSV/JSON-friendly tables.
- JSON to CSV → Clean v1: clean · Tabular extraction feeds cleanup and normalization.
- Clean v1 → Merge pipeline: merge · Cleaned district files are merged into consolidated datasets.
- Raw crawlers → API merge: district feeds · Multiple district inputs are merged into API-facing datasets.
- District cleaning → Geo enrich: enrich · Demographic cleaning and MRT processing produce feature-enriched tables.
- Geo enrich → Real-price merge: build table · Geographic and demographic features are folded into the final modeling dataset.
- Merge pipeline → Real-price merge: source data · Merged housing data contributes to the real-price training table.
- API merge → Real-price merge: source data · API merge outputs also feed the consolidated modeling table.
- Real-price merge → Training entry: train on · Training consumes the prepared modeling dataset.
- Training entry → Model artifacts: persist · Training emits LightGBM model artifacts.
- API entry → Predict API: route · FastAPI exposes prediction endpoints.
- API entry → Recommend API: route · FastAPI exposes recommendation endpoints.
- API entry → Trends API: route · FastAPI exposes market trend endpoints.
- API entry → Static maps: load refs · Serving code loads district and MRT reference maps.
- Predict API → Model artifacts: infer · Prediction uses the trained price models.
- Predict API → Static maps: encode · Inference depends on static geography encodings.
- HTML views → API entry: calls · Template pages are rendered by the main API app.
- Legacy API → Static maps: uses · Legacy API/dashboard also depends on static geography data.
- Quant dashboard → Static maps: uses · Quant dashboard reads district and station metadata.
- Final price app → Static maps: uses · Alternative price app uses the same geography reference assets.
- Final price app → Model artifacts: infer · Alternative app can also consume trained price artifacts.