Building a Home Valuation Model for a Metropolitan Housing Market
Machine LearningModel answerLast updated
Design a production ML system that estimates residential sale prices across a large city, covering features, leakage-safe validation, modeling, fairness, deployment and error analysis.
You are asked to build a machine learning system that estimates the sale price of residential properties across a large city. It will be used as an automated valuation tool, so its outputs may influence lending or pricing decisions.
Describe your design for the following areas.
-
Features and engineering
- Which signals would you use (location, transit access, school quality, neighborhood effects, timing of the sale, broader economic conditions)?
- How would you turn raw data into features, for example distances to points of interest or features that summarize nearby sales?
- How would you encode categorical variables with very many levels?
-
Validation and metrics
- How would you split data so that neither time nor geography leaks information into evaluation?
- Which metrics would you report, and why?
-
Modeling and interpretability
- Compare gradient-boosted trees, random forests, and a linear model with interactions.
- Which would you choose, and how would you explain individual predictions?
-
Fairness and compliance
- How would you detect and mitigate proxies for protected characteristics, such as historical redlining patterns?
-
Operations
- How would you deploy and monitor the system?
- How would you run ablation studies and analyze errors after launch?
State your assumptions about scale, latency and intended use before you begin.
Hints
Hint 1
Start by clarifying the use case and the target: which sales count as valid (arm's-length only), what latency is needed, and whether regulation applies. These choices drive everything else.
Hint 2
Leakage comes from two directions. Prices drift over time and neighboring sales are near-duplicates, so features built from nearby sales must use only earlier data, and validation must hold out both future periods and whole spatial blocks.
Hint 3
Trees cannot extrapolate a time trend, and exponentiating log-space predictions biases them low. Think about modeling price relative to a market index and about a bias correction, and consider slicing metrics by price band and neighborhood for both accuracy and fairness.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
1. Clarify requirements
- Use case: assume an automated valuation model (AVM) that may feed lending decisions. That brings fair-lending rules (ECOA, Fair Housing Act) and a need for explainable outputs.
- Scale: roughly 1M parcels, about 40k sales per year, 15 years of history (around 600k labeled sales), and 50-200 features. This fits on one machine, so the hard parts are data quality and validation, not distributed training.
- Latency: nightly batch re-scoring of all parcels, plus an online endpoint under about 200 ms.
- Target: arm's-length sale price. Exclude foreclosures, family transfers, token-price sales and bulk portfolio deals, or model them separately.
- Output: point estimate, p10/p90 interval, confidence score, top feature attributions and model version.
2. Data and features
Store every table as-of dated (parcels, improvements and permits, sales, listings, POI and transit layers, school boundaries and scores, macro series). This lets you rebuild features exactly as they were known on each sale date, which is the foundation of leakage control.
- Structural: log living area, lot size, age, effective age (years since last renovation permit), bed/bath ratios, condition grade.
- Geospatial: latitude/longitude, rotated coordinates (helps trees split diagonally), H3 cells at several resolutions, elevation, flood zone, distance to water or parks.
- Transit: network walk time to the nearest station (not straight-line), stations within 15 minutes, jobs reachable within 45 minutes.
- POI: counts and distance-decay sums, e.g. Σ exp(−d/λ), for amenities and nuisances such as highways and industrial sites.
- Schools: scores for the boundary in force at sale time.
- Spatial lags: median price per sq ft of the k nearest sales in the prior 6-12 months, excluding the subject, plus a repeat-sales index per submarket. This is usually the strongest feature group and also the largest leakage risk.
- Time and macro: time index, city price index at the sale date, mortgage rates, unemployment, inventory. All lagged to what was known at prediction time.
High-cardinality categoricals (zip, neighborhood, street, builder): out-of-fold target encoding with smoothing toward a parent level (cell, then neighborhood, then city), computed only from earlier data. Alternatives are native categorical handling in CatBoost or LightGBM (ordered statistics resist leakage) or embeddings for neural models. Avoid one-hot encoding thousands of levels.
3. Validation and metrics
Two leakage channels exist.
- Temporal: use rolling-origin evaluation. Train through month T, validate on T+1 to T+3, roll forward, and recompute every lag and encoding strictly from pre-T data.
- Spatial: a neighbor sold the same month is almost a duplicate, so random K-fold overstates accuracy. Use blocked CV by H3 cell or neighborhood, with a buffer (say 500 m) removed from training around each validation block.
Final scheme: hold out the latest ~6 months as a test set. Inside training, use forward-chaining folds that also hold out spatial blocks. Report two regimes separately: "next quarter, known neighborhood" and "unseen neighborhood", since they answer different business questions.
Metrics
- Primary: RMSE on log price (RMSLE), because errors are proportional and luxury homes should not dominate.
- Industry: median absolute percentage error and share within ±10%.
- Intervals: empirical coverage of p10-p90.
- Slices: price decile, neighborhood, property type, and demographic proxies.
Predictions exponentiated from log space are biased low; apply a smearing correction or calibrate on held-out data.
4. Models and interpretability
| Model | Strengths | Weaknesses |
|---|---|---|
| Hedonic linear with interactions and splines | Transparent, stable, regulator-friendly | Manual nonlinearity and spatial structure |
| Random forest | Robust, little tuning | Larger, usually less accurate, cannot extrapolate |
| GBM (LightGBM/CatBoost) | Best tabular accuracy, interactions, missing values, monotone constraints | Less transparent, cannot extrapolate trends |
Recommendation: a GBM on log price with monotone constraints (price non-decreasing in area, baths, school score). Because trees cannot extrapolate time, predict price relative to the current market index and multiply back. Use quantile GBMs or conformal prediction for intervals. Keep the hedonic model as benchmark and fallback, and consider blending with a comparable-sales kNN estimate, which often gives a modest gain.
Interpretability: SHAP summaries and partial dependence for global behavior; per-prediction SHAP values and nearest comparable sales for local explanations, which also support adverse-action reasons.
5. Fairness and compliance
- Never use protected attributes directly. Audit proxies: neighborhood encodings, historical redlining boundaries, and demographic composition of tracts.
- Compare error by demographic group of the area: bias (mean signed error) and accuracy (MdAPE) per group. Systematic undervaluation of minority-majority areas is the key red flag.
- Mitigate by removing or coarsening problematic features, constraining the model, post-hoc calibration per segment, and testing for less discriminatory alternatives with similar accuracy.
- Document everything in model cards and keep audit logs, with human review for contested valuations.
6. Deployment and monitoring
- A feature store with point-in-time joins ensures training and serving use identical logic. Batch features are precomputed nightly; spatial lags are refreshed as new sales arrive.
- Version models and data snapshots; ship with shadow mode, then canary rollout.
- Monitor input drift (PSI on key features), prediction drift, and, once sales close, realized error by segment with the lag that implies. Alert on rising bias or interval under-coverage.
- Retrain monthly or quarterly, and trigger earlier if the market index moves sharply (rate shocks).
7. Ablations and error analysis
- Ablations: drop feature groups (spatial lags, transit, schools, macro) under the same blocked temporal CV, and compare against the hedonic baseline. Check whether gains persist in the unseen-neighborhood regime, where spatial-lag features often matter less.
- Error analysis: inspect the worst residuals by segment (very high price, sparse areas, new construction, unrecorded renovations). Typical causes are stale condition data, bad sale records, and thin comparables. Feed findings back into data cleaning and feature work.
Common mistakes
- Random K-fold CV, which inflates accuracy.
- Spatial-lag or target-encoding features that include the subject property or future sales.
- Ignoring the time trend and relying on trees to extrapolate.
- Reporting only aggregate error, hiding bias against specific areas.
- Skipping bias correction after log transforms.