How do you measure whether two variables deviate together?

cov combines products of paired deviations. Off-diagonal entries describe how two variables vary together.

numpy.cov in practice

The sample covariance of [1,2,3] and [2,4,6] is two. Converting the second measurement to smaller units increases the numerical covariance, so report the units.

import numpy as np
np.cov([1,2,3],[2,4,6])

Result [[1.0, 2.0], [2.0, 4.0]]

中文

如何看两项测量是否一起偏离各自均值?

cov 汇总成对离均差的乘积。协方差矩阵的非对角项描述两个变量的共同变化。

numpy.cov 算例

两组测量 [1,2,3] 和 [2,4,6] 的样本协方差为 2。把第二组换算成更小的单位会放大数值,报告时应注明计量单位。

import numpy as np
np.cov([1,2,3],[2,4,6])

结果 [[1.0, 2.0], [2.0, 4.0]]

References / 参考来源

Keep reading / 继续阅读