Regression forests, rule extraction, regime interpretation, and representative-tree compression.
RANDOM_FOREST builds a nonlinear ensemble of regression trees from a response series and one or more explanatory series. It can be used to explore nonlinear relationships, interactions, and threshold effects. Forest outputs may be inspected through EXTRACT.
# Monthly U.S. employment and candidate explanatory variables
y=DIFF(SERIES_SINCE(PAYEMS,20000101))
a=LAG(DIFF(SERIES_SINCE(INDPRO,20000101)),1)
b=LAG(DIFF(SERIES_SINCE(CPIAUCSL,20000101)),1)
rf=RANDOM_FOREST(LIST(y,a,b),TREES:500,MAX_DEPTH:12,MIN_LEAF:5,MTRY:1,SEED:42)
EXTRACT(rf,slideshow)
The first series in the list is the response; subsequent series are predictors. Align observations and choose lags to reflect when data would actually have been available. The options shown are examples, not universally optimal settings.
| Option | Purpose |
|---|---|
TREES | Number of trees in the ensemble. |
MAX_DEPTH | Maximum depth of individual trees. |
MIN_LEAF | Minimum observations in a terminal leaf. |
MTRY | Number of candidate predictors considered at a split. |
SEED | Random seed for reproducibility. |
Use EXTRACT(rf,output) to inspect fitted results, interpretability views, and diagnostics. The following outputs are supported in the current RainbowStats forest implementation.
| Extract | Description |
|---|---|
slideshow | Combined forest analysis and visual summaries. |
regression | Regression-oriented model summary. |
equation | Model/equation representation. |
rules | Individual decision-tree rules. |
regimes | Threshold-based regimes identified from the forest. |
consolidate_rules | Consolidated rules across trees. |
rules_charts | Visual presentation of rules. |
rules_bar_chart | Rule-frequency or rule-related bar-chart view. |
predictor_bar_charts | Predictor-oriented bar charts. |
tree_removal | Representative-tree selection and pruning analysis. |
compression_chart | Fidelity-versus-complexity table and chart. |
representative_rules | Rules for the selected representative trees. |
representative_consolidated_rules | Consolidated rules for the selected trees. |
representative_regimes | Threshold regimes derived from representative trees. |
A large forest can contain hundreds of trees and thousands of terminal regions. Representative-tree selection identifies a smaller collection of trees that closely reproduces the predictions of the original forest on the observations used for compression. This helps distinguish broad recurring relationships from detailed, potentially redundant splits.
# Explore complexity and fidelity
EXTRACT(rf,tree_removal)
EXTRACT(rf,compression_chart)
EXTRACT(rf,representative_rules)
EXTRACT(rf,representative_consolidated_rules)
EXTRACT(rf,representative_regimes)
In a RainbowStats experiment using ECB daily GBP/EUR log returns from 2020 onward, representative trees reproduced the original forest increasingly closely as more trees were retained. The number of broad threshold regimes grew far more slowly than the number of exact consolidated rules.
| Representative trees | RMSE vs full forest | Exact consolidated rules | Regimes |
|---|---|---|---|
| 5 | 0.000432 | 199 | 16 |
| 10 | 0.000278 | 467 | 17 |
| 20 | 0.000157 | 924 | 17 |
| 50 | 0.000062 | 2,412 | 19 |
These figures illustrate a practical interpretability result: a forest may have many detailed rules but relatively few broad regimes. The regimes are descriptions of this fitted model, not proof of stable economic relationships.
# Daily GBP/EUR log returns with lagged candidate predictors
g=ECB(EXR.D.GBP.EUR.SP00.A)
r=LOGDIFF(SERIES_SINCE(g,20200101))
a=LAG(r,1)
b=LAG(r,2)
m=DISCOVER_MODEL(LIST(r,a,b),MIN_LAG:1,MAX_LAG:6,MAX_VARIABLES:1,SEED:42)
EXTRACT(m,slideshow)
EXTRACT(m,compression_chart)
DISCOVER_MODEL integrates genetic variable selection, forest modeling, and an OLS comparison. The MIN_LAG option is a DISCOVER_MODEL setting, not a RANDOM_FOREST parameter. In the example, predictors are already manually lagged, so the additional search lag must be considered when interpreting the final model.
In the GBP/EUR experiment, the discovered model's chronological holdout RMSE was approximately 0.002240, versus 0.002142 for a historical-mean baseline; test R² was about −0.094. Better compression fidelity did not establish superior forecasting accuracy. For trading applications, forecast performance must be followed by point-in-time backtesting with transaction costs, slippage, and risk controls.
Run the RainbowStats research presentation · Why Bother? — AI and the efficient-market hypothesis