Decision Trees interview question

Machine LearningDecision TreesGradient BoostingForecastinghard

A gradient-boosted tree model was trained on months 1–36 of demand, using month_index as a feature. Its forecast for months 37–48 is the flat line in the plot. Why does it look like this, and what is the fix?

10015020025010203040MonthUnits soldend of training dataActual demandTree model forecast
  1. AThe model underfits the trend because its trees are too shallow; increasing max_depth and n_estimators will let it continue the upward slope beyond month 36.
  2. BEach tree is piecewise constant in month_index, so every month after 36 lands in the same leaf as month 36; model the trend separately, e.g. by detrending.
  3. CThe learning rate is too low, so boosting stops before reaching the newest months; raising it or adding early-stopping patience will extend the trend into the future.
  4. DThe forecast is flat because month_index was not scaled; trees need standardized inputs to extrapolate, so scaling the feature will restore the upward trend.
Show the answer and explanation

Correct answer: B, Each tree is piecewise constant in month_index, so every month after 36 lands in the same leaf as month 36; model the trend separately, e.g. by detrending.

Explanation Decision Trees

A tree partitions the feature space into regions and predicts a constant in each leaf (an average of training targets or, in boosting, of residuals). Every split threshold on month_index lies inside the training range, so in each tree months 37–48 fall into the same leaf as month 36, and the ensemble repeats its month-36 fit (about 204, close to the average of the last few training months). Tree models therefore cannot extrapolate a trend; a random forest cannot even leave the range of the training targets.

Common fixes:

  • Detrend or difference: predict the change yₜ − yₜ₋₁ or the ratio to a trend, then add the trend back.
  • Hybrid model: fit a linear or time-series model for trend and seasonality, and let the trees model the residuals using lags, promotions and calendar features.
  • Use models with linear leaves (e.g. LightGBM linear_tree), or classical/neural forecasting models where trend extrapolation matters.
  • Replace the raw time index with lag and rolling features of the detrended or differenced series; lags of the raw level leave the training range just as the index does.

Why the distractors fail: more depth or more trees only add finer steps inside the training range. The learning rate controls step size per round, not the range of predictions. Trees split on thresholds and depend only on the order of feature values, so scaling month_index moves the thresholds but leaves every prediction unchanged.

Interview tip: this is a frequent senior-level trap in pricing, demand and revenue forecasting. Say explicitly: "tree ensembles interpolate but do not extrapolate, so I handle the trend outside the trees and validate with a time-based split."

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 Machine Learning questions

  1. A telecom churn model (3% churners) is evaluated with the code below and reports a mean CV recall of 0.99. On customers that were set aside before any…
  2. An insurer has 3,000 claims confirmed as fraud and 120,000 claims nobody has investigated. A calibrated classifier trained to separate confirmed (s = 1) from…
  3. A helpdesk routes tickets with a KNN classifier using Euclidean distance on TF-IDF vectors built with norm=None (no length normalisation). Tickets range from…
  4. For a declined credit-card application, an Anchors explainer returns the rule IF utilization > 0.80 AND missed_payments_12m ≥ 2 THEN decline, with precision…
  5. A payments company's fraud team reports F1 and ROC-AUC, yet trains its classifier with gradient descent on log loss. A product manager asks: "Why not minimise…