Hoeffding Anytime tree: it can change its mind¶
A Hoeffding tree picks a question once and keeps it for ever, even if the data later show that
another question is better. The Hoeffding Anytime tree, HoeffdingAnytimeTreeClassifier, does
not: every so often it re-checks the questions it has already asked, and when a different
question has clearly become the better one, it replaces the old one. So it can start acting
early, with a first rough tree, and it keeps improving that tree while the data arrive. It is
also called the Extremely Fast Decision Tree (Manapragada et al. 2018).
Gamestory¶
New Year's Eve in London. A mysterious thief is emptying the banks of the city.
On his trail there is a young detective. At the beginning, to understand where the thief will strike, the detective fixates on a first main question: "Is the bank located near the river? Yes or no?"
A stubborn detective (the normal Hoeffding tree) would keep asking that same first question for the whole night, even if by now it is useless. Our detective instead reasons like a Hoeffding Anytime tree: he is fast at getting a first idea to act immediately, but every now and then he stops to recheck whether his main question is still the best one.
In the middle of the night, the thief stops choosing the banks near the river and starts striking only those without guards. The detective takes a little while to notice, because he wants to collect enough proof before changing his mind. But as soon as the new clues exceed the old ones, he does a brilliant thing: he replaces his first question with the new one ("Are there guards at night?"), making all his reasoning much cleaner and faster.
1. Changing a split that is no longer the best¶
At first variable a tells the state; after 3000 samples a stops mattering and b does. The
Hoeffding tree never revisits a split; the Hoeffding Anytime Tree re-checks every internal node
every grace_period samples and replaces its split when another one wins by the bound.
import numpy as np
from dense_armor.core.online.tree import HoeffdingAnytimeTreeClassifier, HoeffdingTreeClassifier
rng = np.random.default_rng(2)
ht = HoeffdingTreeClassifier(grace_period=100)
ef = HoeffdingAnytimeTreeClassifier(grace_period=100)
for i in range(12000):
y = int(rng.random() < 0.5)
a = rng.normal(3.0 * y if i < 3000 else 0.0, 0.5)
b = rng.normal(3.0 * y if i >= 3000 else 0.0, 0.5)
ht.learn_one({"a": a, "b": b}, y)
ef.learn_one({"a": a, "b": b}, y)
print(ht.root_.split_feature_, ef.root_.split_feature_, ef.n_replaced_)
The Hoeffding tree keeps its first question on a forever; the Anytime tree moved its root to
b (2 splits replaced in total). It changes its mind only once the statistics of all the
samples it has seen favour the new split, so it is slow after a sudden change: the next step is
faster.

The figure follows the same stream for 12000 samples. The two bars are the question at the root
of each tree: the plain tree asks about a for ever; the Anytime tree asks about a until
sample 6600, 3600 samples after the change, and about b after it. The accuracy (top) stays
near 1.0 for both here, because the leaves below the root keep learning; what changes is the
question the tree asks first, which is what explain_one shows to a person.
API reference¶
efdt ¶
Hoeffding Anytime Tree classifier.
The Hoeffding tree (Domingos and Hulten 2000) decides to split a leaf only when the best candidate attribute beats the second best by more than the Hoeffding bound, and it never revisits that decision. The Hoeffding Anytime Tree (HATT) of Manapragada et al. 2018 changes both points:
- a leaf splits as soon as the best candidate beats no split by more than the bound (Manapragada et al. 2018, Function 3.2);
- an internal node re-evaluates its own split every
grace_periodsamples that reach that node, and replaces the split when the best attribute beats the current one by more than the bound (Function 3.3). When no split is significantly better, the node becomes a leaf again.
Every node on the path of a sample updates its own sufficient
statistics in learn_one (Algorithm 3.1, the foreach node in
path loop).
Examples:
>>> import numpy as np
>>> from dense_armor.core.online.tree.efdt import HoeffdingAnytimeTreeClassifier
>>> rng = np.random.default_rng(0)
>>> h = HoeffdingAnytimeTreeClassifier(grace_period=30)
>>> for _ in range(400):
... x = float(rng.normal(0.0 if rng.random() < 0.5 else 5.0, 0.4))
... y = 0 if x < 2.5 else 1
... _ = h.learn_one({"x": x}, y=y)
>>> h.predict_one({"x": 0.1}) != h.predict_one({"x": 5.0})
True
References
Manapragada, C., Webb, G. I., Salehi, M. (2018). Extremely fast decision tree. In KDD, Algorithm 3.1, Functions 3.2 and 3.3. Domingos, P., Hulten, G. (2000). Mining high-speed data streams. In KDD.
HoeffdingAnytimeTreeClassifier ¶
HoeffdingAnytimeTreeClassifier(
grace_period: int = 200,
delta: float = 1e-07,
tau: float = 0.05,
max_depth: int | None = None,
max_nodes: int | None = None,
leaf: str = "nb",
criterion: str = "entropy",
splitter: str = "class_means",
n_splits: int = 10,
nominal_attributes: Any = None,
max_active_leaves: int | None = 1000,
memory_period: int = 1000,
quantile_radius: float | None = None,
)
Bases: HoeffdingTreeClassifier
Hoeffding Anytime Tree classifier.
Same interface and same leaf classifiers as
:class:HoeffdingTreeClassifier. Memory grows with the number of
nodes; max_nodes (default None) can bound the total. Every node keeps
its statistics, because an internal node is re-evaluated; the leaves are
managed by max_active_leaves as in the base class.
budget_s = 1e-3 s: p99 of learn_one measured at 2.8e-5 s on a
2000-sample, two-feature stream on a desktop CPU (default
parameters); the budget leaves room for slower machines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grace_period
|
int
|
minimum samples at a node before a split attempt and the interval between re-evaluations of an internal node. |
200
|
delta
|
float
|
one minus the confidence of the Hoeffding bound. |
1e-07
|
tau
|
float
|
tie threshold. |
0.05
|
max_depth
|
int | None
|
maximum depth, or |
None
|
max_nodes
|
int | None
|
maximum number of nodes, or |
None
|
leaf
|
str
|
|
'nb'
|
criterion
|
str
|
|
'entropy'
|
splitter
|
str
|
numeric splitter, as in :class: |
'class_means'
|
n_splits
|
int
|
candidate thresholds of the |
10
|
nominal_attributes
|
Any
|
categorical features, as in :class: |
None
|
max_active_leaves
|
int | None
|
leaves that keep statistics, as in :class: |
1000
|
memory_period
|
int
|
samples between two memory checks. |
1000
|
quantile_radius
|
float | None
|
slot width of the |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
on a bad |
Source code in dense_armor/core/online/tree/efdt.py
Details¶
- Anytime tree: every
grace_periodsamples each internal node re-evaluates its candidate splits on the statistics of all the samples that went through it; the replacement follows Manapragada et al. (2018), Algorithm 3.1 and Functions 3.2 and 3.3. The options of the Hoeffding tree (criterion,splitter,nominal_attributes,max_active_leaves) are inherited, see the Hoeffding tree. - Sources: Manapragada, C., Webb, G. I., Salehi, M. (2018), "Extremely fast decision tree", arXiv:1802.08780.