Skip to content

Mean

Running mean.

Attributes

  • n (float)

    The current sum of weights. If each passed weight was 1, then this is equal to the number of seen observations.

Examples

from river import stats

X = [-5, -3, -1, 1, 3, 5]
mean = stats.Mean()
for x in X:
    mean.update(x)
    print(mean.get())
-5.0
-4.0
-3.0
-2.0
-1.0
0.0

You can calculate a rolling average by wrapping a utils.Rolling around:

from river import utils

X = [1, 2, 3, 4, 5, 6]
rmean = utils.Rolling(stats.Mean(), window_size=2)

for x in X:
    rmean.update(x)
    print(rmean.get())
1.0
1.5
2.5
3.5
4.5
5.5

Methods

get

Return the current value of the statistic.

revert
update

Update the called instance.

Parameters

  • x'numbers.Number'
  • w — defaults to 1.0

update_many