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:
... print(mean.update(x).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:
... print(rmean.update(x).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 and return the called instance.
Parameters
- x (numbers.Number)
- w β defaults to
1.0
update_many
ReferencesΒΆ
-
West, D. H. D. (1979). Updating mean and variance estimates: An improved method. Communications of the ACM, 22(9), 532-535. β©
-
Finch, T., 2009. Incremental calculation of weighted mean and variance. University of Cambridge, 4(11-5), pp.41-42. β©
-
Chan, T.F., Golub, G.H. and LeVeque, R.J., 1983. Algorithms for computing the sample variance: Analysis and recommendations. The American Statistician, 37(3), pp.242-247. β©