Skip to content


Lossy Count with Forgetting factor1.

Keep track of the most frequent item(set)s in a data stream and apply a forgetting factor to discard previous frequent items that do not often appear anymore. This is an approximation algorithm designed to work with a limited amount of memory rather than accounting for every possible solution (thus using an unbounded memory footprint). Any hashable type can be passed as input, hence tuples or frozensets can also be monitored.

Considering a data stream where n elements were observed so far, the Lossy Count algorithm has the following properties:

  • All item(set)s whose true frequency exceeds support * n are output. There are no false negatives

  • No item(set) whose true frequency is less than (support - epsilon) * n is outputted

  • Estimated frequencies are less than the true frequencies by at most epsilon * n


  • support (float) – defaults to 0.001

    The support threshold used to determine if an item is frequent. The value of support must be in \([0, 1]\). Elements whose frequency is higher than support times the number of observations seen so far are outputted.

  • epsilon (float) – defaults to 0.005

    Error parameter to control the accuracy-memory tradeoff. The value of epsilon must be in \((0, 1]\) and typically epsilon \(\ll\) support. The smaller the epsilon, the more accurate the estimates will be, but the count sketch will have an increased memory footprint.

  • alpha (float) – defaults to 0.999

    Forgetting factor applied to the frequency estimates to reduce the impact of old items. The value of alpha must be in \((0, 1]\).


  • name


>>> from river import datasets
>>> from river import stats

>>> dataset = datasets.TREC07()
>>> lc = stats.LossyCount()

>>> for x, _ in dataset.take(10_000):
...     lc.update(x["sender"])

>>> counts = lc.get()
>>> for sender in counts:
...     print(f"{sender}    {lc[sender]:.2f}")
Groupe Desjardins / AccesD <>    2494.79
Groupe Desjardins / AccesD <>    77.82
" Alert" <>    67.15
<>    56.22
"Bank of America Inc." <>    28.37    22.95    15.98
Michael Adam <>    5.99    4.00
"Zachary Kline" <>    3.99
Jonathan Worthington <>    2.99
charles loboz <>    2.00    2.00



Return the current value of the statistic.


Update and return the called instance.


  • x (Hashable)


  1. Veloso, B., Tabassum, S., Martins, C., Espanha, R., Azevedo, R., & Gama, J. (2020). Interconnect bypass fraud detection: a case study. Annals of Telecommunications, 75(9), 583-596.