Residual Modeling
Interpretable, Counterfactual Valuation of Icelandic Homes. A valuation model for Icelandic residential property built as a stack of gradient-boosted residual layers. A sale price is treated as a product of independent signals: the property itself, its broad location, the local market around it, liquidity and timing, and the agency that sold it. In house-price-index-deflated log-price space each signal becomes an additive term, and each LightGBM layer is trained on the residual the layers before it leave. The estimate is therefore a sum of attributable parts, and every valuation comes back as krónur contributed by each layer rather than as one opaque number. The same model answers counterfactual questions: change the floor area, rooms, floor, construction year or selling agency, and it re-prices the home and shows which layers moved.
General notes
- Gradient-boosted residual stacking: one LightGBM model per layer, each fitted to what the earlier layers could not explain, in HPI-deflated log-price space.
- Interpretable by construction: every valuation returns the krónur contributed by structure, broad location, local market, and liquidity and timing, each layer with its own cross-validated R², ready for a waterfall chart.
- Counterfactual pricing: a batch scenarios endpoint re-prices a property under changed rooms, floor area, lot size, floor, construction year, property type, postal code, view or selling agency, and returns the price delta and the per-layer breakdown for each scenario.
- Comparables done properly: the local-market layer learns only comparable-sale deltas, anchored on the frozen structure-and-location prediction and recomputed out of fold, so training and serving use the same comparables.
- Leakage hunted down: early cross-validation scores of 94.5% traced back to asking-price and assessment leakage and random splits. The model is now judged only on time-ordered out-of-fold sales.
Construction notes
- Agency effects use empirical-Bayes shrinkage per agency, so small agencies are pulled toward the market rather than over-fitted.
- A listing-presentation layer is quarantined until it beats the holdout: it raised cross-validation scores without improving held-out sales.
- Spatial structure combines a postal-area prior with a continuous-coordinate residual, promoted to depth 10 after an ablation study.
- Every trained model carries its lineage, and the serving cache is refreshed from the production artifacts so the API and the model never disagree.
- Served end to end: precomputed market baselines in Postgres, live inference that applies agency effects on request, a FastAPI service and a Next.js valuation app with a waterfall of layer contributions and a scenarios panel.
12,709 time-ordered out-of-fold sales in the evaluation
6.6% median absolute error across all sales
5.9% median absolute error for apartments (9,507 sales)
11 packages in a uv workspace with an enforced dependency graph
Materials
- Python
- LightGBM
- Postgres/PostGIS
- FastAPI
- Next.js
- Pydantic
- uv workspace
- Project
- Hákon Freyr Gunnarsson
- Sheet
- Detail F
- Title
- Residual Modeling
- Scale
- N.T.S.
- Rev
- 2026-10
Live valuation
Explore the current model for apartments in Iceland’s capital area. Look up a property, inspect how Structure, Location and Time contribute to its estimated price, and compare scenarios. Agency and photo features are not active in this model.
- Project
- Hákon Freyr Gunnarsson
- Sheet
- Detail F.1
- Title
- Live valuation
- Scale
- N.T.S.
- Rev
- 2026-10