Extra Trees: Extremely Randomized Trees

Extra Trees : Guide Complet — Arbres Extrêmement Aléatoires

Extra Trees

Summary

Extra Trees (Extremely Randomized Trees) are an ensemble learning method that takes the randomization of Random Forest even further. Instead of searching for the best split point for each candidate feature, Extra Trees selects a completely random split point for each feature, then keeps the best among these random splits. This radically simple strategy leads to models that are remarkably fast to train, often competitive in accuracy, and particularly robust against overfitting. This article guides you through the mathematical foundations, intuition, Python implementation, and concrete use cases of Extra Trees.


Mathematical Principle

From the decision tree to the random ensemble

A classic decision tree constructs each node by evaluating all available features and all possible thresholds for each feature, in order to maximize a purity criterion — most often information gain or the Gini index. Formally, for a given node t, the algorithm searches for the combination that maximizes impurity reduction across all features and all candidate thresholds.

where j denotes the feature, s the split threshold, and Sₕ the set of all candidate thresholds for feature j.

Random Forest: a first dose of randomness

Random Forest introduces a first layer of randomization: instead of examining all p features, each node randomly draws a subset of m features (m < p), then searches for the best threshold among those.

Extra Trees: two levels of randomness

Extra Trees go much further. The fundamental difference lies in one crucial point:

Instead of searching for the optimal threshold among the m randomly drawn features, Extra Trees draws a completely random threshold for each candidate feature, then chooses the best among these m random splits.

Formally, each node proceeds as follows:

  1. Randomly draw m features from the p available (without replacement).
  2. For each selected feature, draw a threshold s uniformly from the [min, max] range of observed values for that feature in the parent node.
  3. Evaluate the split criterion for each of the m (feature, threshold) pairs.
  4. Keep the pair that maximizes impurity reduction.

This double randomization — random selection of features and thresholds — fundamentally distinguishes Extra Trees from other tree-based ensemble methods.


Intuition: Why More Randomness Can Improve Performance

The paradox of excessive randomization

If Random Forest chooses the best split among a subset of features, Extra Trees go further: they don’t even look for the best split — they split at random.

This seems counterintuitive. How could a less informed split criterion lead to a better overall model?

The answer lies in the variance reduction theory specific to ensemble methods.

Individual variance vs. ensemble variance

Each individual tree in an Extra Trees model is indeed less accurate than a tree in a Random Forest. The split criterion being random, each tree’s quality is reduced. But here’s the paradox: the trees also become much less correlated.

The variance of an ensemble estimator decomposes approximately as: Ensemble Variance ≈ average correlation between trees × individual tree variance.

where average correlation measures the similarity between tree predictions and individual variance reflects the accuracy of each tree taken in isolation. By massively increasing randomization, Extra Trees considerably reduce the correlation between trees, which more than compensates for the decrease in individual tree quality.

Intuitive analogy

Imagine you need to estimate the weight of a bag of rice. If you ask ten people who all use the same rough reasoning, their answers will be systematically biased in the same direction. On the other hand, if everyone uses a radically different method — some estimate by eye, others compare to known references, others do calculations — individual errors, while potentially larger, cancel each other out and the average converges to the truth.

Extra Trees exploit exactly this principle: each tree explores the feature space in a radically independent way, producing a more robust ensemble consensus.


Python Implementation with Scikit-Learn

Environment setup

Here is a complete implementation comparing Extra Trees and Random Forest on the same dataset:

import time
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import make_classification, load_breast_cancer
from sklearn.model_selection import train_test_split, cross_val_score
from sklearn.ensemble import ExtraTreesClassifier, RandomForestClassifier
from sklearn.metrics import (
    accuracy_score, classification_report,
    confusion_matrix, roc_auc_score
)
from sklearn.preprocessing import StandardScaler

# Reproducibility configuration
np.random.seed(42)

# Load dataset
dataset = load_breast_cancer()
X, y = dataset.data, dataset.target
feature_names = dataset.feature_names

# Train / test split
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.2, random_state=42, stratify=y
)

# Standardization
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)

Training and direct comparison

# --- Extra Trees ---
start_et = time.perf_counter()
et_model = ExtraTreesClassifier(
    n_estimators=200,
    max_features='sqrt',
    max_depth=None,
    min_samples_split=2,
    min_samples_leaf=1,
    bootstrap=False,
    random_state=42,
    n_jobs=-1
)
et_model.fit(X_train_scaled, y_train)
time_et = time.perf_counter() - start_et

# Extra Trees predictions
y_pred_et = et_model.predict(X_test_scaled)
y_proba_et = et_model.predict_proba(X_test_scaled)[:, 1]

# --- Random Forest ---
start_rf = time.perf_counter()
rf_model = RandomForestClassifier(
    n_estimators=200,
    max_features='sqrt',
    max_depth=None,
    min_samples_split=2,
    min_samples_leaf=1,
    bootstrap=True,
    random_state=42,
    n_jobs=-1
)
rf_model.fit(X_train_scaled, y_train)
time_rf = time.perf_counter() - start_rf

# Random Forest predictions
y_pred_rf = rf_model.predict(X_test_scaled)
y_proba_rf = rf_model.predict_proba(X_test_scaled)[:, 1]

# --- Performance comparison ---
print("=" * 60)
print("COMPARISON: Extra Trees vs Random Forest")
print("=" * 60)

acc_et = accuracy_score(y_test, y_pred_et)
acc_rf = accuracy_score(y_test, y_pred_rf)
auc_et = roc_auc_score(y_test, y_proba_et)
auc_rf = roc_auc_score(y_test, y_proba_rf)

print(f"\n{'Metric':<30} {'Extra Trees':<15} {'Random Forest':<15}")
print("-" * 60)
print(f"{'Accuracy':<30} {acc_et:<15.4f} {acc_rf:<15.4f}")
print(f"{'ROC AUC':<30} {auc_et:<15.4f} {auc_rf:<15.4f}")
time_label = "Training time (s)"
print(f"{time_label:<30} {time_et:<15.4f} {time_rf:<15.4f}")

# Cross-validation for robustness
scores_et = cross_val_score(et_model, X_train_scaled, y_train, cv=5, scoring='accuracy')
scores_rf = cross_val_score(rf_model, X_train_scaled, y_train, cv=5, scoring='accuracy')

cv_label = "CV Accuracy (mean ± std)"
print(
    f"\n{cv_label:<30} "
    f"{scores_et.mean():.4f} ± {scores_et.std():.4f}    "
    f"{scores_rf.mean():.4f} ± {scores_rf.std():.4f}"
)

Feature importance

# Feature importance visualization
et_importances = et_model.feature_importances_
rf_importances = rf_model.feature_importances_

# Sort by descending importance (Extra Trees)
indices = np.argsort(et_importances)[::-1][:10]

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(14, 6))

# Extra Trees
ax1.barh(range(10), et_importances[indices][::-1], color='steelblue')
ax1.set_yticks(range(10))
ax1.set_yticklabels([feature_names[i] for i in indices][::-1], fontsize=8)
ax1.set_title('Extra Trees \u2014 Feature Importance', fontweight='bold')
ax1.set_xlabel('Average importance')

# Random Forest
ax2.barh(range(10), rf_importances[indices][::-1], color='darkorange')
ax2.set_yticks(range(10))
ax2.set_yticklabels([feature_names[i] for i in indices][::-1], fontsize=8)
ax2.set_title('Random Forest \u2014 Feature Importance', fontweight='bold')
ax2.set_xlabel('Average importance')

plt.tight_layout()
plt.savefig('extra_trees_vs_rf_importance.png', dpi=150, bbox_inches='tight')
plt.show()

# Detailed classification report
print("\n" + "=" * 60)
print("CLASSIFICATION REPORT \u2014 Extra Trees")
print("=" * 60)
print(classification_report(y_test, y_pred_et, target_names=dataset.target_names))

# Confusion matrix
cm = confusion_matrix(y_test, y_pred_et)
print(f"\nConfusion matrix:\n{cm}")

What you will typically observe

When running this code, several trends consistently emerge:

  • Training time: Extra Trees are significantly faster than Random Forest. Random threshold search eliminates the sorting of feature values, which is the most expensive operation in Random Forest. On moderately sized data, the speedup is typically 2x to 5x.
  • Predictive performance: Extra Trees achieve comparable accuracy, sometimes slightly lower, sometimes slightly higher depending on the dataset. On the Breast Cancer Dataset, both methods regularly exceed 96% accuracy.
  • Feature importance: Both models generally identify the same features as the most important, but Extra Trees tend to produce more uniformly distributed importance scores, reflecting their lower bias toward features with many continuous values.

Key Hyperparameters

Understanding and properly tuning hyperparameters is essential to get the best out of Extra Trees. Here are the most influential parameters:

n_estimators (default: 100)

The number of trees in the forest. The more trees, the more stable the prediction, at the cost of proportional computation time. In practice, 200 to 500 trees are an excellent trade-off for most tasks. Unlike Random Forest, you can often use more trees with Extra Trees because each tree is much faster to build.

max_features (default: 'sqrt' in classification)

The number of features randomly drawn at each node. Common values are:
– 'sqrt' : √p features (recommended for classification)
– 'log2' : log₂(p) features (for highly decorrelated sets)
– None : all features (very random split, useful as a comparison baseline)

A lower value increases randomization and reduces correlation between trees, which is particularly advantageous with Extra Trees where the very nature of the split is already highly random.

max_depth (default: None)

The maximum depth of each tree. By default (None), trees grow until all leaves are pure or contain fewer than min_samples_split samples. Extra Trees are less sensitive to overfitting than individual trees thanks to the extreme randomization of splits, which often allows keeping max_depth=None.

min_samples_split (default: 2)

The minimum number of samples required to split an internal node. Increasing this value (e.g., to 5 or 10) acts as an additional regularizer, particularly useful on noisy or small datasets.

bootstrap (default: False)

This is a major difference from Random Forest. By default, Extra Trees do not use bootstrap — each tree is trained on the entire training dataset. The additional randomization comes only from the random choice of split thresholds, not from data sampling.

However, it is possible to enable bootstrap=True to combine both sources of randomization, which can be useful on very high-dimensional data.


Advantages and Limitations

Advantages

  1. Superior training speed: Since Extra Trees do not search for optimal thresholds, they avoid the costly sorting step that dominates computation in Random Forest. On high-dimensional or large-scale data, the time savings are substantial — often a factor of 2x to 10x.
  2. Less sensitive to overfitting: The increased split randomization acts as a powerful intrinsic regularizer. Individual trees are less capable of memorizing training data noise.
  3. Reduced feature selection bias: Random Forest favors continuous features with many modalities for split selection because they offer more candidate thresholds. Extra Trees eliminate this bias since each feature receives exactly one random threshold, regardless of its cardinality.
  4. Good performance with little tuning: The strong randomization makes the model naturally robust. Default hyperparameters work reasonably well in most situations without requiring an extensive grid search.
  5. Scalability: Extra Trees are particularly well-suited to large datasets thanks to their speed and natural parallelization.

Limitations

  1. Sometimes lower performance than Random Forest: On small datasets where searching for optimal thresholds provides a net benefit, Extra Trees may achieve slightly lower accuracy.
  2. Reduced interpretability: Individual trees are even harder to interpret than in Random Forest, since thresholds do not correspond to any intrinsic structure in the data.
  3. Less studied theoretically: Although Extra Trees benefit from a solid theoretical framework, the academic literature is less abundant than for Random Forest, making some behavioral aspects less well understood.
  4. May underperform with little data: The strong randomization requires a sufficient number of trees for the law of large numbers to fully play out. With little training data, the bias-variance trade-off can shift unfavorably.

4 Concrete Use Cases

1. High-dimensional text document classification

Extra Trees excel on text classification problems where the number of features (n-grams, TF-IDF) can exceed tens of thousands. In this context, the exhaustive search for optimal thresholds in Random Forest becomes very expensive, while Extra Trees effectively exploit high dimensionality through their extreme randomization.

from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.ensemble import ExtraTreesClassifier
from sklearn.pipeline import Pipeline

pipeline = Pipeline([
    ('tfidf', TfidfVectorizer(max_features=5000, ngram_range=(1, 2))),
    ('clf', ExtraTreesClassifier(n_estimators=300, max_features='sqrt', n_jobs=-1))
])
pipeline.fit(documents_train, labels_train)

2. Real-time anomaly detection

In industrial monitoring or cybersecurity systems, training and prediction speed are critical. Extra Trees, with their ultra-fast training and ability to efficiently identify normal patterns, are a preferred choice for anomaly detection in streaming data.

3. Preliminary feature selection

Before training a more complex model (neural network, XGBoost), Extra Trees offer a fast and reliable mechanism for evaluating feature importance. Their lower bias toward continuous variables makes them a more equitable selection tool than classic Random Forest.

4. Processing massive tabular data

For machine learning competitions (Kaggle) or industrial applications involving millions of rows and hundreds of columns, Extra Trees provide an extremely competitive baseline in minimal time. Their combination of speed, robustness, and good performance makes them a first model to systematically try in any tabular data workflow.


Conclusion

Extra Trees represent an elegant and powerful extension of the Random Forest concept. By replacing optimal threshold search with random drawing, they demonstrate that in ensemble learning, more randomness at the individual level can lead to more robustness at the collective level.

Training speed, resistance to overfitting, and low sensitivity to hyperparameters make Extra Trees an indispensable tool in any machine learning practitioner’s toolbox. Even though in certain specific cases Random Forest retains a slight accuracy advantage, the speed gain of Extra Trees often fully justifies their adoption — especially during initial exploration of a new dataset.


See Also

About Salah YAHIAOUI

Salah YAHIAOUI publie sur The Pingouin des tutoriels Python et des décryptages sur l’intelligence artificielle. Les cas pratiques récents précisent leurs données, leurs tests et leurs limites. À propos, méthode éditoriale et contact.

View all posts by Salah YAHIAOUI →