Skip to content

PearsonCorr

Online Pearson correlation.

Parameters

  • ddof – defaults to 1

    Delta Degrees of Freedom.

Attributes

  • var_x (stats.Var)

    Running variance of x.

  • var_y (stats.Var)

    Running variance of y.

  • cov_xy (stats.Cov)

    Running covariance of x and y.

Examples

>>> from river import stats

>>> x = [0, 0, 0, 1, 1, 1, 1]
>>> y = [0, 1, 2, 3, 4, 5, 6]

>>> pearson = stats.PearsonCorr()

>>> for xi, yi in zip(x, y):
...     print(pearson.update(xi, yi).get())
0
0
0
0.774596
0.866025
0.878310
0.866025

You can also do this in a rolling fashion:

>>> from river import utils

>>> x = [0, 0, 0, 1, 1, 1, 1]
>>> y = [0, 1, 2, 3, 4, 5, 6]

>>> pearson = utils.Rolling(stats.PearsonCorr(), window_size=4)

>>> for xi, yi in zip(x, y):
...     print(pearson.update(xi, yi).get())
0
0
0
0.7745966692414834
0.8944271909999159
0.7745966692414832
-4.712160915387242e-09

Methods

get

Return the current value of the statistic.

revert
update

Update and return the called instance.

Parameters

  • x
  • y