1. Home
  2. Dimitri Bianco

Jul 5

Why decision trees fail to forecast beyond your training data

3 min → 0:59

Overview

Host Dimitri Bianco compares decision tree regression, raw ordinary least squares regression, and log-transformed regression to show the trade-offs of each method when modeling and forecasting non-linear data.

3 things to know

Bianco says log inputs let linear models fit curves

Dimitri Bianco demonstrates that taking the log of the input variable lets a linear model fit curved data with a 0.993 R-squared and forecast past the training data window.

More

This approach combines a tight curve fit with interpretable coefficients and the ability to forecast beyond the right-hand boundary of the training data.

▶ Watch at 2:45

Bianco: Decision trees cannot forecast past training data limits

Dimitri Bianco points out that decision trees cannot continue a trend line beyond the minimum and maximum values of the training data, making them unsuitable for forecasting outside observed ranges.

More

This makes them unsuitable when the primary goal is forecasting outside the observed data range.

▶ Watch at 2:45

Bianco shows strong summary numbers can hide awful fits

Dimitri Bianco shows that fitting a straight line model to curved data can produce an R-squared of 0.797 and 0.000 p-values while missing the curve with a 399.61 error.

More

Fitting an un-transformed OLS regression to non-linear data can produce textbook "good" summary statistics, including an R-squared of 0.797 (Adjusted R-squared of 0.796, F-statistic of 3907) and p-values of 0.000 for both the intercept (coefficient of -86.7965) and the $X$ variable (coefficient of 46.8174).

▶ Watch at 1:38

Also in this episode

Bianco: Smoother decision tree curves require much more complex models

Dimitri Bianco explains that decision trees predict using step functions, so getting a smoother curve takes a much more complex tree, though a four-layer tree fits capped data well.

More

When encountering non-linear data, jumping to a non-linear model like a 4-layer decision tree yields a strong in-sample fit (achieving a Mean Squared Error of 21.27 on the 1,000-sample dataset). However, if the problem is cross-sectional, capped, and will not see negative values below 0,0, a decision tree is very appropriate.

▶ Watch at 0:22

Bianco notes practitioners usually keep a 0.052 p-value constant

Dimitri Bianco notes that in the log-transformed linear model, the constant has a 0.052 p-value, but practitioners usually ignore intercept p-values and probably should not remove the constant.

More

Even though this exceeds the standard 0.05 threshold, practitioners typically do not pay much attention to intercept p-values and probably should not remove the constant, though this requires expertise and judgment. Additionally, the transformed OLS model may not be useful if the problem requires preventing the model from scoring values less than zero.

▶ Watch at 2:51

Quotes

“But when we jump to the actual prediction forecast here, you can see it is awful, right? Directionally it's okay, it's missing the entire non-linear piece here, the fact that it's not capturing the non-linearity, and the fact that the model errors are going to be large, as the mean squared error for this model is going to be 399.61.”

▶ Watch at 1:53

“We could actually use the coefficients in this output here to actually do some interpretation, some understanding, and we can forecast clearly above and beyond the window towards the right of the X values.”

▶ Watch at 3:21

“Now, one drawback of decision trees is the fact that they do not continue on in the forecasting and prediction realm here.”

▶ Watch at 0:38

Full summary

Episode Overview

  • The host compares decision tree regression, un-transformed Ordinary Least Squares (OLS) regression, and log-transformed OLS regression to demonstrate the trade-offs of each approach when modeling non-linear data.
  • Starting with a 4-layer decision tree on a 1,000-observation dataset, the episode illustrates how tree-based models capture curves via step functions but fail to extrapolate trends beyond the boundaries of the training data.
  • The narrative then shifts to OLS regression, showing how fitting a raw linear model to a curved dataset produces misleadingly strong summary statistics alongside massive prediction errors.
  • Finally, the host demonstrates how applying a logarithmic transformation to the input variable allows OLS regression to accurately trace the non-linear curve, provide interpretable coefficients, and forecast outside the existing data window.

Key Concepts

  • Decision Trees Excel at Bounded, Cross-Sectional Data: When encountering non-linear data, jumping to a non-linear model like a 4-layer decision tree yields a strong in-sample fit (achieving a Mean Squared Error of 21.27 on the 1,000-sample dataset). Because decision trees predict using a built-in step function based on split points, achieving a smoother curve requires a much more complex tree, which conflicts with the goal of keeping models simple. However, if the problem is cross-sectional, capped, and will not see negative values below 0,0, a decision tree is very appropriate.
  • The Extrapolation Limitation of Decision Trees: Decision trees cannot continue a trend line beyond the minimum and maximum values of the training data (for example, when future data moves past $X = 5$ on a chart where training data ends between 4 and 5). This makes them unsuitable when the primary goal is forecasting outside the observed data range.
  • Good Summary Statistics Can Mask a Terrible Model Fit: Fitting an un-transformed OLS regression to non-linear data can produce textbook "good" summary statistics, including an R-squared of 0.797 (Adjusted R-squared of 0.796, F-statistic of 3907) and p-values of 0.000 for both the intercept (coefficient of -86.7965) and the $X$ variable (coefficient of 46.8174). Despite these numbers, the visual fit is "awful" because a straight line misses the curve entirely, resulting in a massive Mean Squared Error (MSE) of 399.61, though the host notes there could still be a specific use case for it.
  • Variable Transformation Unlocks OLS Forecasting and Interpretability: By taking the $\log(X)$ of an input variable that follows a logarithmic curve, a linear OLS model can fit non-linear data with an R-squared of 0.993 (Adjusted R-squared of 0.993, F-statistic of 1.367e+05) and a statistically significant $X$ coefficient of 1.6491 (p-value of 0.000). This approach combines a tight curve fit with interpretable coefficients and the ability to forecast beyond the right-hand boundary of the training data.
  • Nuances of Intercept P-Values and Lower-Bound Scoring: In the log-transformed OLS model, the constant (const) has a coefficient of 0.5098 and a p-value of 0.052. Even though this exceeds the standard 0.05 threshold, practitioners typically do not pay much attention to intercept p-values and probably should not remove the constant, though this requires expertise and judgment. Additionally, the transformed OLS model may not be useful if the problem requires preventing the model from scoring values less than zero.

Quotes

  • At 0:38 - "Now, one drawback of decision trees is the fact that they do not continue on in the forecasting and prediction realm here." - Explaining why tree-based models fail when asked to predict values of $X$ beyond the bounds of the training data.
  • At 1:53 - "But when we jump to the actual prediction forecast here, you can see it is awful, right? Directionally it's okay, it's missing the entire non-linear piece here, the fact that it's not capturing the non-linearity, and the fact that the model errors are going to be large, as the mean squared error for this model is going to be 399.61." - Highlighting the danger of relying solely on R-squared (0.797) and significant p-values (0.000) without visually inspecting the model's predictions.
  • At 3:21 - "We could actually use the coefficients in this output here to actually do some interpretation, some understanding, and we can forecast clearly above and beyond the window towards the right of the X values." - Demonstrating the primary advantages of using a log-transformed OLS regression over a decision tree.

Takeaways

  • Always plot your model's predictions against the actual data rather than relying solely on R-squared or p-values, as even a model with a 0.993 or 0.797 R-squared requires visual inspection to confirm it is actually a good fit.
  • Define the boundaries of your problem before selecting an algorithm: use a decision tree if your data is cross-sectional, capped, and strictly bounded above zero, but switch to a transformed OLS regression if you need to interpret coefficients or forecast beyond the maximum values of your current dataset.
  • Exercise judgment when evaluating regression tables by keeping the intercept term (const) intact even if its p-value sits slightly above the 0.05 threshold (such as 0.052), rather than automatically dropping it from the model.

Watch the full episode 3 min

Read along with the audio summary

The host reveals how a model with textbook good summary statistics can still have an awful visual fit and massive prediction errors.

Decision trees excel at bounded, cross sectional data. A four layer tree on a thousand samples gets a low average squared error of about twenty one.

However, decision trees cannot forecast beyond your data. If training data ends below five, the tree cannot continue a trend past five.

Good statistics can mask a terrible fit. A standard Ordinary Least Squares line gets an R squared fit score near point eight, yet the host notes its average squared error is nearly four hundred.

Transforming variables unlocks forecasting. Taking the logarithm of the input gives the linear model a point nine nine R squared fit.

Know the nuances of intercept p values. You probably should not remove the constant even if its p value sits slightly above point zero five, though this requires expertise and judgment.

Plot your predictions against actual data, because even a point nine nine R squared requires visual inspection to confirm a good fit.

More from Dimitri Bianco

Related Episodes