RANDOM_FOREST

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.

Basic usage

# 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.

Configuration

OptionPurpose
TREESNumber of trees in the ensemble.
MAX_DEPTHMaximum depth of individual trees.
MIN_LEAFMinimum observations in a terminal leaf.
MTRYNumber of candidate predictors considered at a split.
SEEDRandom seed for reproducibility.

Extracting forest results

Use EXTRACT(rf,output) to inspect fitted results, interpretability views, and diagnostics. The following outputs are supported in the current RainbowStats forest implementation.

ExtractDescription
slideshowCombined forest analysis and visual summaries.
regressionRegression-oriented model summary.
equationModel/equation representation.
rulesIndividual decision-tree rules.
regimesThreshold-based regimes identified from the forest.
consolidate_rulesConsolidated rules across trees.
rules_chartsVisual presentation of rules.
rules_bar_chartRule-frequency or rule-related bar-chart view.
predictor_bar_chartsPredictor-oriented bar charts.
tree_removalRepresentative-tree selection and pruning analysis.
compression_chartFidelity-versus-complexity table and chart.
representative_rulesRules for the selected representative trees.
representative_consolidated_rulesConsolidated rules for the selected trees.
representative_regimesThreshold regimes derived from representative trees.

Forest compression and 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)
Important: The compression RMSE measures agreement between the reduced and full forests on the observations used for compression. It does not measure out-of-sample forecast error, economic significance, or trading profits. Counts of exact consolidated rules are descriptive complexity measures, not statistical effective degrees of freedom.

Example: GBP/EUR forest compression

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 treesRMSE vs full forestExact consolidated rulesRegimes
50.00043219916
100.00027846717
200.00015792417
500.0000622,41219

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.

End-to-end discovery example

# 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.

Interpreting results responsibly

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.

Related research

Run the RainbowStats research presentation · Why Bother? — AI and the efficient-market hypothesis