Feature Engineering interview question

Preprocessing & Feature EngineeringFeature EngineeringDecision Treeseasy

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?

  1. AStandardize latitude and longitude first: the two coordinates have different ranges, and trees otherwise split mostly on the one with the larger range, which creates the blocky map.
  2. BReplace the coordinates with their product latitude × longitude, so that a single interaction feature lets every split use both coordinates at once instead of one axis at a time.
  3. CDrop latitude and longitude: trees split raw coordinates at fixed grid intervals, so these features mostly add noise, and the blocky map is a sign of overfitting to them.
  4. DAdd 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.
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.

Practice it as a quiz

Answer this and the other free questions with instant grading, streaks and weak-topic tracking, or unlock all 4,000 questions.

More Preprocessing & Feature Engineering questions

  1. How do MCAR, MAR and MNAR differ in what the probability of a value being missing depends on?
  2. What does one-hot encoding do to a categorical feature such as color with the values red, green and blue?
  3. In model training and evaluation, what does the term data leakage mean?
  4. What is a main reason to perform feature selection before training a model?
  5. A temperature sensor produced 20 readings: 17 between 48 and 52, plus 99, 100 and 101. The table shows their summary statistics. A rule that flags z > 3 using…