Implementation:Online ml River Stats Count
| Knowledge Sources | |
|---|---|
| Domains | Online_Learning, Statistics |
| Last Updated | 2026-02-08 16:00 GMT |
Overview
Count is a simple counter that tracks the number of observations seen in a data stream.
Description
This statistic maintains a running count of the number of observations processed. It increments by one with each update call, regardless of the value passed (the value parameter is optional). This is one of the most fundamental statistics used in online learning for tracking sample size.
Usage
Use Count when you need to track how many observations have been processed in a stream. This is essential for calculating other statistics that depend on sample size, monitoring data throughput, or implementing sampling strategies based on observation counts.
Code Reference
Source Location
- Repository: Online_ml_River
- File: river/stats/count.py
Signature
class Count(stats.base.Univariate):
def __init__(self):
self.n = 0
Import
from river import stats
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| x | Any | No | Value to update with (ignored, can be None) |
Outputs
| Name | Type | Description |
|---|---|---|
| get() | int | Current count of observations |
Usage Examples
from river import stats
# Create a counter
count = stats.Count()
# Update with values (values are optional)
data = [1, 2, 3, 4, 5]
for x in data:
count.update(x)
print(f"Processed {count.get()} observations")
# Output:
# Processed 1 observations
# Processed 2 observations
# Processed 3 observations
# Processed 4 observations
# Processed 5 observations
# Can also update without values
count_simple = stats.Count()
for _ in range(10):
count_simple.update()
print(f"Total count: {count_simple.get()}")
# Output: Total count: 10