Skip to content

Piecewise Linear Model Trees & Quinlan M5/Cubist Rules

Standard gradient boosting libraries (LightGBM, XGBoost, CatBoost) and classical CART trees share a fundamental architectural limitation: they approximate smooth continuous response surfaces using orthogonal step functions (piecewise constant leaves).

Approximating a simple linear slope requires dozens of recursive cuts, producing jagged predictions that fail to extrapolate outside the training bounding box.

mltreelib.ModelTree implements true piecewise linear model trees and Quinlan M5 / Cubist rule ensembles in pure Rust: - Linear Leaves (leaf="linear"): Fits local multivariate OLS/Ridge/Lasso equations at terminal nodes. - Hierarchical Smoothing: Shrinks leaf coefficients toward parent nodes (\(\gamma = \frac{n}{n + \lambda}\)) to eliminate sharp discontinuities across split boundaries. - Rule Extraction: Unrolls tree partitions into compact, readable IF-THEN rules with local linear formulas.

flowchart LR
    A["Raw Predictors X"] --> B["Recursive Partitioning\nMinimizing Local Residual Variance"]
    B --> C["Node Partition 1\ny = 14.2 + 0.85*x1 - 1.2*x2"]
    B --> D["Node Partition 2\ny = 8.1 + 2.10*x1 + 0.4*x2"]
    B --> E["Node Partition 3\ny = 31.5 - 0.40*x1 + 3.8*x2"]

    C --> F["Hierarchical Leaf Shrinkage\nShrink toward Ancestor Equation"]
    D --> F
    E --> F

    F --> G["Smooth Continuous Prediction\nExtrapolates Linear Trends"]

    classDef blueBox fill:#1e3a8a,stroke:#3b82f6,stroke-width:2px,color:#ffffff;
    classDef greenBox fill:#14532d,stroke:#22c55e,stroke-width:2px,color:#ffffff;
    classDef grayBox fill:#334155,stroke:#64748b,stroke-width:2px,color:#ffffff;

    class A,B grayBox;
    class C,D,E blueBox;
    class F,G greenBox;

1. Step Functions vs Linear Leaves (The Diamond Price Benchmark)

The table below comes from a separate benchmark on real diamond sales (OpenML 42225). It compares a standard 0D constant CART tree, a 100-tree GBDT ensemble, and a shallow ModelTree (max_depth=3, 8 linear leaves). That benchmark is not regenerated on this page.

The runnable block under the table is a different, synthetic setup: one 2,000-row price surface, 1,500 rows for training and 500 for testing, with one ModelTree. Its test RMSE is not comparable with the table, because the data, sample sizes and models differ.

Decision Tree Step Functions vs Continuous Linear Leaves

Local Linear Planes Across Diamond Partitions

Benchmark Results

Model Architecture Leaf Type Tree Depth / Ensembles Test RMSE Interpretation
CART Baseline 0D Constant Mean Depth 6 (64 leaves) $1,280 Jagged staircases; zero extrapolation
GBDT (LightGBM) 0D Constant Sum 100 Trees (Depth 4) $742 Hundreds of orthogonal step boundaries
ModelTree (mltreelib) 1D Linear OLS Depth 3 (8 leaves) $695 Smooth continuous planes on the real diamond benchmark (not reproduced by the block below)
import numpy as np
from mltreelib import ModelTree, Metrics

# 1. Generate non-linear diamond price surface with carat and cut interactions
rng = np.random.default_rng(2026)
n_samples = 2000

carat = rng.uniform(0.3, 3.5, n_samples)
depth = rng.uniform(58.0, 65.0, n_samples)
table = rng.uniform(53.0, 62.0, n_samples)

# Price surface with non-linear exponential carat scaling
price = 1500.0 * (carat ** 1.8) - 15.0 * depth + rng.normal(0, 150.0, n_samples)

X = np.column_stack([carat, depth, table])
feature_names = ["carat", "depth", "table"]

train_idx = range(1500)
test_idx = range(1500, 2000)

# 2. Train shallow ModelTree with piecewise linear leaves
tree = ModelTree(
    leaf="linear",
    max_depth=3,
    min_rows=30,
    l2=1e-3,
    shrinkage=5.0,  # Hierarchical leaf shrinkage
)
tree.fit(X[train_idx], price[train_idx].tolist(), col_names=feature_names)
pred = tree.predict(X[test_idx])

rmse = Metrics().regression(price[test_idx].tolist(), pred)["rmse"]
print(f"Piecewise Linear ModelTree Test RMSE: ${rmse:.2f}")
Piecewise Linear ModelTree Test RMSE: $155.99

Next: turn the fitted linear leaves into IF-THEN rules, because the M5 and Cubist step is what makes each leaf's equation auditable.

2. Quinlan M5 & Cubist Rule Extraction (Concrete Compressive Strength)

On industrial concrete mixtures (OpenML 4353), local chemistry and curing age interact continuously. Quinlan's M5 tree architecture partitions the design space and converts leaves into auditable linear rules. The block below fits a small linear-leaf tree on the local Concrete parquet (800 shuffled rows) and extracts its rules.

Concrete Compressive Strength Decision Tree

Concrete Strength Local Linear Leaf Planes

Inspecting Extracted Rules and Leaf Equations

import pandas as pd
from mltreelib import ModelTree

from mltreelib import dataset_path
df = pd.read_parquet(dataset_path("concrete_compressive_strength")).sample(frac=1, random_state=2026)
target = "ConcreteCompressiveStrength"
features = df.columns.drop(target).tolist()
concrete_tree = ModelTree(leaf="linear", max_depth=3, min_rows=40)
concrete_tree.fit(df[features].iloc[:800].to_numpy().tolist(),
                  df[target].iloc[:800].tolist(), col_names=features)

# Extract white-box rules directly from the fitted tree
ruleset = concrete_tree.extract_rules()
print(f"Extracted {len(ruleset.rules)} Transparent Rules:")
for r in ruleset.rules:
    print(f"  RULE #{r.id} (Cover: {r.cover} samples, Confidence: {r.confidence:.2f}):")
    print(f"    IF {' AND '.join(r.conditions)}")
    print(f"    THEN Leaf #{r.leaf_id} prediction = {r.prediction:.2f}")
Extracted 7 Transparent Rules:
  RULE #1 (Cover: 333 samples, Confidence: 0.95):
    IF Cement > 164.6000 AND Cement <= 350.0000 AND Age > 14.0000
    THEN Leaf #4 prediction = 39.96
  RULE #2 (Cover: 134 samples, Confidence: 0.95):
    IF Cement <= 350.0000 AND Age <= 7.0000
    THEN Leaf #0 prediction = 16.11
  RULE #3 (Cover: 102 samples, Confidence: 0.95):
    IF Cement <= 164.6000 AND Age > 14.0000
    THEN Leaf #3 prediction = 25.93
  RULE #4 (Cover: 74 samples, Confidence: 0.95):
    IF Cement > 350.0000 AND Age <= 14.0000
    THEN Leaf #2 prediction = 34.80
  RULE #5 (Cover: 68 samples, Confidence: 0.95):
    IF Cement > 350.0000 AND Water <= 181.1000 AND Age > 14.0000
    THEN Leaf #5 prediction = 63.13
  RULE #6 (Cover: 48 samples, Confidence: 0.95):
    IF Cement > 350.0000 AND Water > 181.1000 AND Age > 14.0000
    THEN Leaf #6 prediction = 44.97
  RULE #7 (Cover: 41 samples, Confidence: 0.95):
    IF Cement <= 350.0000 AND Age > 7.0000 AND Age <= 14.0000
    THEN Leaf #1 prediction = 27.85

Next: shrink leaf coefficients toward the parent node, because the smallest extracted rule (Rule 7, 41 samples) falls in the N < 50 range, where unregularized OLS has high variance.

3. Hierarchical Leaf Shrinkage

In small leaf partitions (\(N < 50\)), unregularized OLS fits are vulnerable to high variance. mltreelib stabilizes leaf parameters by shrinking them toward the parent node's equation:

\[\hat{\boldsymbol{\beta}}_\text{leaf}^* = \gamma \hat{\boldsymbol{\beta}}_\text{leaf} + (1 - \gamma) \hat{\boldsymbol{\beta}}_\text{parent}, \qquad \gamma = \frac{n}{n + \lambda}\]

Setting shrinkage=10.0 prevents overfitting in sparse leaves while retaining sharp local adaptation in data-rich regimes.

Related guides