A gradient-boosted house-price model for Istanbul uses raw latitude and longitude as features. Prices are highest around a few prime districts and along the Bosphorus, which runs diagonally across the latitude/longitude grid, and the model's price map shows blocky, staircase-shaped regions. Which change most likely helps?
Show the answer and explanation
Correct answer: D, Add distances to each prime district and to the Bosphorus as extra features: tree splits are axis-aligned, so round or diagonal price zones otherwise come out as staircases.
Explanation Feature Engineering
Tree models split on one feature at a time, so every boundary is axis-aligned: a split on latitude is a horizontal line on the map, a split on longitude a vertical one. A round zone of high prices around a district, or a band along a diagonal shoreline, can only be approximated by a staircase of many small rectangles. That costs many splits, needs lots of data and generalises poorly between the steps.
Feature engineering gives the trees shapes they can split on directly:
- Distance to key locations (the most direct fix here): haversine distance to each prime district or metro station, plus distance to the Bosphorus shore. One split on a point distance is a circle on the map; on the shore distance, a band along the strait.
- Rotated coordinates: lat + lon and lat − lon align only with 45° diagonals, so add rotations at several angles; a diagonal shoreline is then close to axis-aligned in one of them.
- Geohash, grid or cluster IDs (e.g. k-means on coordinates), often target-encoded out of fold, to capture neighbourhood effects.
Haversine distance: d = 2R·asin(√(sin²(Δφ/2) + cos φ₁·cos φ₂·sin²(Δλ/2))), with latitudes φ, longitudes λ and R ≈ 6,371 km.
Why the alternatives fail: trees are invariant to monotonic rescaling of a feature, so standardization changes nothing. Replacing both coordinates with lat × lon collapses the map into one number, so unrelated places along hyperbola-shaped curves share a value. Trees pick thresholds anywhere, not on a fixed grid, and raw coordinates carry real signal, just inefficiently for curved or diagonal boundaries, so dropping them throws it away.
Interview tip: mention that linear models need these features even more, because raw latitude can only express one straight north–south gradient.