Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Online ml River Tree Nodes HATR

From Leeroopedia


Knowledge Sources
Domains Online_Learning, Decision_Trees
Last Updated 2026-02-08 16:00 GMT

Overview

Hoeffding Adaptive Tree Regressor (HATR) node implementations with drift detection and alternate subtree management for regression tasks.

Description

This module implements adaptive nodes for Hoeffding Adaptive Tree regressors. The AdaLeafRegressor monitors prediction errors using variance statistics and drift detectors. When drift is detected in branch nodes (AdaBranchRegressor), alternate subtrees are grown and evaluated using statistical tests (z-tests) to determine if they should replace the main subtree. Supports mean prediction, model-based prediction, and adaptive prediction strategies.

Usage

Use HATR nodes when building regression trees that must adapt to concept drift in non-stationary data streams. The statistical testing approach ensures reliable subtree replacement decisions.

Code Reference

Source Location

Signature

class AdaLeafRegressor(HTLeaf):
    def __init__(self, stats, depth, splitter, drift_detector, rng, **kwargs):
        ...
    def learn_one(self, x, y, *, w=1.0, tree=None, parent=None, parent_branch=None):
        ...

class AdaBranchRegressor(DTBranch):
    def __init__(self, stats, *children, drift_detector, **attributes):
        ...
    def learn_one(self, x, y, *, w=1.0, tree=None, parent=None, parent_branch=None):
        ...
    def kill_tree_children(self, tree):
        ...

class AdaLeafRegMean(AdaLeafRegressor, LeafMean):
    ...

class AdaLeafRegModel(AdaLeafRegressor, LeafModel):
    ...

class AdaLeafRegAdaptive(AdaLeafRegressor, LeafAdaptive):
    ...

Import

from river.tree.nodes.hatr_nodes import AdaLeafRegressor
from river.tree.nodes.hatr_nodes import AdaBranchRegressor
from river.tree.nodes.hatr_nodes import AdaLeafRegMean

I/O Contract

Input Type Description
x dict Feature dictionary
y float Target value
w float Sample weight (default 1.0)
drift_detector DriftDetector Drift detection algorithm instance
Output Type Description
prediction float Predicted target value
error_tracker Var Variance statistics of prediction errors

Usage Examples

from river.tree.nodes.hatr_nodes import AdaLeafRegMean
from river.drift import ADWIN
from river.tree.splitter import EBSTSplitter
import random

# Create adaptive regression leaf
rng = random.Random(42)
leaf = AdaLeafRegMean(
    stats=None,  # Var() will be created
    depth=1,
    splitter=EBSTSplitter(),
    drift_detector=ADWIN(),
    rng=rng
)

# Update with samples
x = {'feature1': 0.5, 'feature2': 1.2}
leaf.learn_one(x, y=25.5, w=1.0, tree=None)

# Get prediction (mean value)
pred = leaf.prediction(x, tree=None)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment