Skip to content

Cov

Covariance.

Parameters

  • ddof

    Default1

    Delta Degrees of Freedom.

Attributes

  • n

Examples

from river import stats

x = [-2.1,  -1,  4.3]
y = [   3, 1.1, 0.12]

cov = stats.Cov()

for xi, yi in zip(x, y):
    cov.update(xi, yi)
    print(cov.get())
0.0
-1.044999
-4.286

This class has a revert method, and can thus be wrapped by utils.Rolling:

from river import utils

x = [-2.1,  -1, 4.3, 1, -2.1,  -1, 4.3]
y = [   3, 1.1, .12, 1,    3, 1.1, .12]

rcov = utils.Rolling(stats.Cov(), window_size=3)

for xi, yi in zip(x, y):
    rcov.update(xi, yi)
    print(rcov.get())
0.0
-1.045
-4.286
-1.382
-4.589
-1.415
-4.286

Methods

get

Return the current value of the statistic.

revert
update

Update and return the called instance.

Parameters

  • x
  • y
  • w — defaults to 1.0

update_many

Notes

The outcomes of the incremental and parallel updates are consistent with numpy's batch processing when \(\text{ddof} \le 1\).


  1. Wikipedia article on algorithms for calculating variance 

  2. Schubert, E. and Gertz, M., 2018, July. Numerically stable parallel computation of (co-) variance. In Proceedings of the 30th International Conference on Scientific and Statistical Database Management (pp. 1-12).