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 Rules AMRules

From Leeroopedia


Knowledge Sources
Domains Online_Learning, Rule_Learning, Regression, Concept_Drift, Anomaly_Detection
Last Updated 2026-02-08 16:00 GMT

Overview

Adaptive Model Rules (AMRules) is a rule-based online regression algorithm that builds and maintains a set of decision rules with built-in drift detection and anomaly filtering capabilities.

Description

AMRules constructs rules using the Hoeffding bound similar to Hoeffding Trees, but with several unique features. Each rule has built-in drift detection that triggers rule removal when concepts change. Rules also perform anomaly detection using Chebyshev's inequality on feature distributions, skipping training on anomalous instances after a warm-up period. A default rule handles instances not covered by any specialized rule. Rules expand by adding conditions when sufficient samples are observed. The prediction strategy can be target mean, a regression model (like linear regression), or adaptive selection between them. Rules can operate as an ordered set (first matching rule) or unordered (average of all matching rules).

Usage

Use AMRules for online regression problems where you want interpretable rules and need to handle concept drift and outliers. It is particularly valuable when you want to understand model decisions through rule inspection. Set pred_type='mean' for simple averaging, 'model' for sophisticated predictions, or 'adaptive' to dynamically choose. Use ordered_rule_set=True when rules should be tried in sequence (like decision lists) or False to aggregate predictions from all covering rules. The anomaly_threshold parameter controls outlier sensitivity - more negative values are more conservative. AMRules works well with numerical features; categorical features should be used with pred_type='mean'.

Code Reference

Source Location

Signature

class AMRules(
    n_min: int = 200,
    delta: float = 1e-7,
    tau: float = 0.05,
    pred_type: str = "adaptive",
    pred_model: base.Regressor | None = None,
    splitter: spl.Splitter | None = None,
    drift_detector: base.DriftDetector | None = None,
    fading_factor: float = 0.99,
    anomaly_threshold: float = -0.75,
    m_min: int = 30,
    ordered_rule_set: bool = True,
    min_samples_split: int = 5,
)

Import

from river import rules

I/O Contract

Input
Parameter Type Description
x dict Feature dictionary (numerical features recommended)
y float Target value for regression
Output
Method Return Type Description
predict_one(x) float Prediction from covering rules or default rule
learn_one(x, y) None Updates rules with drift and anomaly detection
anomaly_score(x) tuple (mean_score, std_score, support) for anomaly detection
debug_one(x) str Human-readable explanation of prediction

Usage Examples

from river import datasets
from river import drift
from river import evaluate
from river import metrics
from river import preprocessing
from river import rules

dataset = datasets.TrumpApproval()

model = (
    preprocessing.StandardScaler() |
    rules.AMRules(
        delta=0.01,
        n_min=50,
        drift_detector=drift.ADWIN()
    )
)

metric = metrics.MAE()

result = evaluate.progressive_val_score(dataset, model, metric)
print(result)  # MAE: 1.119553

# Inspect a prediction
from river.datasets import synth
dataset = synth.Friedman(seed=42).take(1001)

model = rules.AMRules(n_min=50, delta=0.1, drift_detector=drift.ADWIN())

for i, (x, y) in enumerate(dataset):
    if i == 1000:
        break
    model.learn_one(x, y)

print(model.debug_one(x))

Related Pages

Page Connections

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