Abstract
River is a machine learning library for dynamic data streams and continual learning. It provides multiple state-of-the-art learning methods, data generators/transformers, performance metrics and evaluators for different stream learning problems. It is the result from the merger of two popular packages for stream learning in Python: Creme and scikit-multiflow. River introduces a revamped architecture based on the lessons learnt from the seminal packages. River's ambition is to be the go-to library for doing machine learning on streaming data. Additionally, this open source package brings under the same umbrella a large community of practitioners and researchers.
Introduction
In traditional "batch" machine learning, models are trained on static datasets that are available all at once. However, many modern applications—such as IoT sensor monitoring, financial transaction analysis, or network log processing—generate data as a continuous, never-ending stream. Batch learning is often unsuitable for these scenarios due to storage costs, high retraining latency, and the phenomenon of "concept drift," where data distributions change over time.
River addresses these challenges by providing a specialized Python library for online machine learning. Born from the merger of Creme and scikit-multiflow, River allows models to learn from data streams one sample at a time, providing a high-performance framework for real-time applications where retraining from scratch is impossible.
Methods and Architecture
River is built on a revamped architecture designed for flexibility and speed, moving beyond a simple code merger. Key technical innovations include:
- The
*_oneAPI: Unlikescikit-learn, which processes arrays, River’s core methods—learn_one,predict_one, andtransform_one—are optimized to handle individual data samples. - Dictionary-Based Data Structures: River uses Python dictionaries (and Cython-optimized variants) as its default data structure. This allows for $O(1)$ lookup and insertion and supports feature evolution, where features can appear or disappear dynamically in the stream.
- Elegant Pipelines: River utilizes a "pipe" operator (
|) to chain scaling, feature engineering, and estimation in a readable, reproducible manner. - Hybrid Learning: While focused on instance-incremental learning, River also supports mini-batches via
_manymethods usingpandas.DataFramesfor cases where data arrives in small chunks.
Performance Benchmarks
The authors evaluated River using the Elec2 benchmark dataset (45,312 samples of electricity pricing data) and various synthetic generators. The results demonstrate that River is a performance leader in both accuracy and computational efficiency.
Accuracy Comparison
River maintains accuracy levels identical to or better than its parent libraries and scikit-learn. As shown in the table below, River's performance across Gaussian Naive Bayes (GNB), Logistic Regression (LR), and Hoeffding Trees (HT) is highly competitive.
Computational Efficiency
River's use of Cython for its computational core allows it to achieve the execution speeds necessary for high-frequency data streams. In the Hoeffding Tree (HT) benchmark, River processed the dataset in just 0.99 seconds, significantly faster than Creme (2.66s) and scikit-multiflow (2.95s).
For Gaussian Naive Bayes (GNB), River’s prediction time (3.27s) was nearly 40% faster than scikit-learn's equivalent in a streaming context (5.43s).
Conclusion and Future Work
River successfully consolidates the strengths of its predecessors into a unified, high-performance toolkit for streaming machine learning. While it excels at model development and testing, the authors identify a gap in canonical deployment methods for online models. Future work includes developing a dedicated library for production deployment and expanding support for complex tasks like multi-label learning and advanced anomaly detection.
Summary updated