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 HTC

From Leeroopedia


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

Overview

Hoeffding Tree Classifier (HTC) leaf node implementations providing different prediction strategies for classification tasks.

Description

This module provides three types of leaf nodes for Hoeffding Tree classifiers. LeafMajorityClass predicts using the majority class and monitors class distributions to determine split promise. LeafNaiveBayes uses Naive Bayes models for prediction when sufficient samples are available. LeafNaiveBayesAdaptive dynamically selects between majority class and Naive Bayes based on which performs better on the observed data.

Usage

Use LeafMajorityClass for simple and fast predictions, LeafNaiveBayes when features provide strong probabilistic information, and LeafNaiveBayesAdaptive when uncertain which strategy will perform better on your data stream.

Code Reference

Source Location

Signature

class LeafMajorityClass(HTLeaf):
    def __init__(self, stats, depth, splitter, **kwargs):
        ...
    def prediction(self, x, *, tree=None):
        ...
    def calculate_promise(self):
        ...
    def observed_class_distribution_is_pure(self):
        ...

class LeafNaiveBayes(LeafMajorityClass):
    def prediction(self, x, *, tree=None):
        ...
    def disable_attribute(self, att_index):
        pass

class LeafNaiveBayesAdaptive(LeafMajorityClass):
    def __init__(self, stats, depth, splitter, **kwargs):
        ...
    def learn_one(self, x, y, *, w=1.0, tree=None):
        ...
    def prediction(self, x, *, tree=None):
        ...

Import

from river.tree.nodes.htc_nodes import LeafMajorityClass
from river.tree.nodes.htc_nodes import LeafNaiveBayes
from river.tree.nodes.htc_nodes import LeafNaiveBayesAdaptive

I/O Contract

Input Type Description
stats dict Class observation counts
depth int Node depth in tree
splitter Splitter Numeric attribute observer
Output Type Description
prediction dict Normalized class probability distribution
promise float Split promise value (higher means more likely to split)

Usage Examples

from river.tree.nodes.htc_nodes import LeafNaiveBayesAdaptive
from river.tree.splitter import GaussianSplitter

# Create adaptive leaf
leaf = LeafNaiveBayesAdaptive(
    stats={'cat': 10, 'dog': 8},
    depth=2,
    splitter=GaussianSplitter()
)

# Learn from samples
x = {'size': 0.5, 'weight': 12.5}
leaf.learn_one(x, y='cat', w=1.0, tree=None)

# Get prediction (automatically chooses best strategy)
pred = leaf.prediction(x, tree=None)
# Returns: {'cat': 0.55, 'dog': 0.45}

# Check if node should split
promise = leaf.calculate_promise()

Related Pages

Page Connections

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