Predict Property Sale Prices from Multi-Year Transaction Records
Machine LearningModel answerLast updated
Design an end-to-end supervised ML pipeline to estimate residential sale prices from historical transaction data, including market shocks and missing values.
Predict Property Sale Prices from Multi-Year Transaction Records
You have access to a database of residential property sales spanning several years. Each record contains property attributes, location data, and the date the transaction occurred. The dataset is messy: some fields have gaps, and the time window includes a major macroeconomic disruption that temporarily broke many of the usual patterns in the market.
Your task is to build a model that estimates what a given property would sell for. This is a discussion question — walk through your reasoning at every step and expect the conversation to go deep on your choices.
Constraints
- The dataset covers multiple years and contains records with missing values in various fields.
- Property attributes may include things like size, number of rooms, age, and type, but no fixed feature list is handed to you — proposing and justifying the features is part of the task.
- The data includes at least one period where market behavior shifted dramatically, so you cannot assume the statistical relationships stay stable over time.
- Predictions are served in batch; low-latency serving is not a requirement unless you choose to introduce one.
- No coding is required, but name concrete algorithms and write out formulas where they clarify your reasoning.
Questions to Resolve Before You Start
Before diving in, consider what clarifying questions you would ask:
- Who uses the predictions, and at what granularity — individual listings, a portfolio of existing properties, or a regional price index?
- Should the model predict what a property would sell for today, or at some point in the future?
- How geographically diverse is the data — one metro area, or many different markets?
- How large is the dataset, which fields have the most missingness, and do any records lack a reliable sale price?
- Are there interpretability requirements — does someone need to understand why a specific property was priced the way it was?
- How often can the model be retrained, and how quickly does it need to respond to market shifts?
Part 1
Define your prediction target precisely and lay out the feature set you would build. Explain how you turn raw transaction records into a labeled training dataset — including how you handle duplicates, outliers, and non-standard transactions.
Part 2
Choose a model family and justify it. Explain specifically why a non-linear model is likely to outperform a linear baseline on this kind of data, referencing concrete characteristics of real-estate transactions. Then define your evaluation metrics and describe your validation strategy.
Part 3
Describe your approach to missing data. How do you select which features to keep, and how do you guard against data leakage — which forms of leakage are most likely here?
Part 4
Markets evolve. How do you monitor the model after deployment to catch degradation? How would your pipeline have handled a sudden, large shock to market behavior?
Hints
Hint 1
The target variable is right-skewed and has multiplicative error structure — think about what transformation makes errors comparable across cheap and expensive properties, and what the back-transformation recovers (mean vs. median).
Hint 2
Random cross-validation will give you an optimistically wrong error estimate. Think about why future market levels and neighborhood comparables can leak into training folds, and design a validation scheme that prevents it.
Hint 3
Drift is not one thing — the mix of properties coming to market, the relationship between features and price, and the noise level can all shift independently. Treating them as one problem leads to poor diagnosis and slow response.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Approach
The interviewer is testing judgment across the full pipeline, not any single algorithm. Strong answers name concrete choices, defend them against alternatives, and honestly describe failure modes. The assumed use case throughout is an automated valuation model (AVM): given a property's attributes and location, estimate what it would sell for on the open market today, produced in batch.
Part 1: Target Definition and Dataset Construction
Prediction target
Predict $y = \log(\text{sale price})$ for arm's-length transactions.
Why log? Prices are right-skewed and their errors are multiplicative. An upgraded kitchen adds roughly a percentage of value, not a fixed dollar amount. Squared error on log price is approximately squared relative error, since $\log \hat{p} - \log p \approx (\hat{p} - p)/p$. This makes a $10%$ miss on a $$200$k condo and a $10%$ miss on a $$2$M house equally costly, which matches business intuitions.
Back-transformation caveat. $\exp(\hat{y})$ estimates the median sale price, not the mean. If the business needs the mean (e.g., for portfolio expected value), apply a smearing correction: $\hat{p} = e^{\hat{y}} \cdot e^{\hat{\sigma}^2/2}$ under Gaussian residuals, or the empirical analog $e^{\hat{y}} \cdot \frac{1}{n}\sum e^{r_i}$ otherwise.
A stronger variant for non-stationary markets. Predict $y = \log p - \log I_{r,t-1}$, where $I_{r,t-1}$ is a lagged regional price index (e.g., a repeat-sales index for that metro). The model learns relative value — how much this specific property deviates from the local market level — and the index carries the market trend separately. This cleanly separates the structural model from macro drift, which is important for Part 4.
Building the dataset
- One row per transaction. De-duplicate and resolve cases where multiple records map to the same sale.
- Remove non-arm's-length transfers: family conveyances, foreclosures, $1 deed transfers, and bulk portfolio moves. Flag them rather than silently dropping, in case the business later wants them for a different task.
- Clip or remove obvious data errors: a single-family home listed at 50,000 sq ft, or a price per square foot in the extreme tail of its regional distribution.
- Crucially: all features must be joined as-of the sale date. Each row may only see information that existed before that transaction closed. Violating this creates leakage.
Feature groups
| Group | Examples |
|---|---|
| Structural | living area, lot size, bedrooms, bathrooms, property age, years since last renovation, stories, garage, condition/quality grade |
| Location | lat/lon, ZIP or geohash, school district ratings, distance to CBD/transit/coast, crime index |
| Market context (lagged) | regional price index at $t-1$ month, 3- and 12-month index momentum, prevailing mortgage rate, inventory levels |
| Comparables | median log price-per-sqft of the $k$ nearest sales in the prior 6–12 months |
| Property history | prior sale price indexed forward to today, time elapsed since last sale |
| Time | sale month (seasonality), year, economic regime indicator |
Part 2: Model Choice and Evaluation
Baseline first. A hedonic linear regression on log price with regional and time fixed effects. It is interpretable, fast to train, and gives a floor that every other model must beat.
Main model: gradient-boosted trees (LightGBM or XGBoost). Non-linear models outperform here for specific, structural reasons:
- Feature interactions. The value added by an extra bedroom depends on location and property type. A linear model needs hand-crafted interaction terms; trees discover them through splits automatically.
- Thresholds and saturation. A fifth bathroom adds very little. Property age is non-monotonic — new construction and historic homes both carry premiums over mid-century stock. Lot size matters in suburban markets but is nearly irrelevant for urban condos.
- Spatial non-linearity. Splits on latitude/longitude can carve out school district boundaries, highway corridors, or waterfront premiums without pre-specifying those boundaries.
- Practical robustness. Trees are invariant to feature scaling, tolerant of outliers in inputs, handle missing values natively via learned split directions, and work well with mixed numeric and categorical features.
Metrics
- RMSE on log price — the training objective, interpretable as approximate relative error.
- Median absolute percentage error (MdAPE) — robust to tail errors and readable by non-technical stakeholders.
- Share of predictions within ±5% and ±10% — the standard AVM accuracy bands used in the industry.
- All metrics should be sliced by region, price decile, and property type. Aggregate numbers hide segment-level failures.
Validation scheme
Use rolling-origin temporal splits: train on all data through month $T$, evaluate on $T+1$ through $T+3$, then roll the window forward. Repeat-fold-style random splits are wrong here for two reasons: they leak future market index levels into training, and they let comparables features from future sales contaminate the past. Expect out-of-time error to be noticeably higher than random-fold error — that gap is the honest estimate to report.
Part 3: Missing Data, Feature Selection, and Leakage
Diagnosing missingness
Before imputing, classify the mechanism:
- MCAR (missing completely at random): simple median/mode imputation is fine.
- MAR (missing conditional on observed variables): e.g., lot size is always missing for condos. Impute within groups (property type × region) using that group's median.
- MNAR (missing because of its own value): e.g., condition grade is absent because the property is distressed. Here the missingness is itself a predictive signal — add a binary
is_missingindicator and do not over-trust the imputed value.
Trees handle NaN natively, so for the GBDT model the main task is adding the indicator columns. For the linear baseline, impute and keep the indicators. Either way, fit all imputers on training data only — fitting them on the full dataset leaks validation statistics into training.
Feature selection
Start from domain knowledge, then validate empirically. Rank features by permutation importance or SHAP values computed on the temporal validation fold — not training-set impurity importance, which is biased toward high-cardinality features. Run group ablations (remove all market context features, measure the delta) and drop any group that does not improve out-of-time error.
Leakage — most likely forms here
- Post-sale fields: tax assessments updated after closing, appraisal values, days-on-market (populated only once the home sells), and any "final" field stamped at close.
- Target-encoded or comp features: must be computed out-of-fold and using only sales that occurred strictly before the prediction date.
- Listing price as a feature: the agent's ask price is powerful but must be excluded unless the use case is explicitly at-listing-time prediction — and even then it risks the model learning to echo the agent rather than value the property independently.
- Smell test: any single feature that causes an implausibly large drop in error warrants a timestamp audit of how that field was generated.
Part 4: Drift Detection and Market Shocks
Three distinct kinds of drift require separate monitors and responses:
| Drift type | What changed | How to detect | Response |
|---|---|---|---|
| Covariate | Distribution of properties coming to market ($P(x)$ shifts) | Population Stability Index (PSI) or KS test per feature; segment volume counts | Audit segment-level performance; reweight or retrain |
| Concept | Relationship between features and price ($P(y\mid x)$ shifts) | Rolling median signed residual by region and month; MdAPE trend over time | Retrain; add recency weighting; update index features |
| Variance | Noise level changes | Rolling IQR of residuals; prediction-interval coverage rate | Recalibrate intervals; investigate market uncertainty |
Handling a sudden market shock
A shock like a pandemic onset breaks the market in ways a static model cannot anticipate. Several design choices help:
- Predicting relative-to-index (from Part 1) insulates the structural model from aggregate level shifts. Update the index separately and frequently using the most recent comparable sales; the structural model stays more stable.
- Recency-weighted retraining deweights stale transactions exponentially. This lets the model adapt faster once new post-shock sales data arrives.
- Regime indicator features (e.g., a lockdown flag or a mortgage-rate-spike flag) can be added retroactively in retraining to teach the model that some periods behave differently.
- Prediction intervals should widen during high-uncertainty periods. Monitor coverage: if your 90% interval is only covering 70% of outcomes, it needs recalibration.
- The honest answer is that no model reliably predicts through a shock with no new data. The correct operational response is to widen uncertainty estimates, increase retraining frequency once new transactions appear, and communicate the elevated uncertainty to downstream consumers rather than silently serving stale predictions.
Common mistakes to avoid
- Using random CV folds on time-series data and reporting that number as the honest error.
- Predicting on raw price without a log transform, then optimizing RMSE — this over-penalizes errors on expensive homes.
- Treating missingness as a nuisance to be filled rather than a signal to be encoded.
- Monitoring only aggregate RMSE in production and missing that one region or price segment has gone badly wrong.
- Conflating model retraining with concept drift resolution — if the features themselves are stale (e.g., the comps window hasn't updated), retraining with stale features does not fix drift.