http://blog.csdn.net/pipisorry/article/details/48770785
Order statistics顺序统计量
皮皮Blog
Averages and variances均值和方差
Correlating相关
Note: 要实现估计量的无偏性,numpy中的方差计算是除以N,而协方差计算是除以N-1,所以会发现单独计算向量的方差并不会与计算两个向量的协方差矩阵对角线上的元素相等!
a= [0, 1, 2] print(np.var(a) * 3 == np.cov(a) * 2, '\n') 输出: True当然可以设置度参数bias : int, optional来改变这种计算模式
皮皮Blog
Histograms直方图、柱状图
皮皮Blog
统计函数cov协方差矩阵计算示例
空间中有三个点,值得注意的是,这三个点是随机变量的观测值,而坐标系x,y(维度)是随机变量!也就是有N个点,这N个点就是观测值,而每个点有K维,K就是随机变量个数!!!
Consider two variables, x0 and x1, which correlate perfectly, but in opposite directions:
>>> x = np.array([[0, 2], [1, 1], [2, 0]]).T
>>> x
array([[0, 1, 2],
[2, 1, 0]])
Note how x0 increases while x1 decreases. The covariance matrix shows this clearly:
>>> np.cov(x)
array([[ 1., -1.],
[-1., 1.]])
Note that element C0;1, which shows the correlation between x0 and x1, is negative.
Further, note how x and y are combined:
>>> x = [-2.1, -1, 4.3]
>>> y = [3, 1.1, 0.12]
>>> X = np.vstack((x,y))
>>> print np.cov(X)
[[ 11.71 -4.286 ]
[ -4.286 2.14413333]]
>>> print np.cov(x, y)
[[ 11.71 -4.286 ]
[ -4.286 2.14413333]]
>>> print np.cov(x)
11.71
3.30.
Note:
1. 上面的X等价于np.array([[-2.1, -1, 4.3], [3, 1.1, 0.12]])
2. 从这里可以看出,cov函数的输入可以是矩阵(二维向量),计算的是矩阵中行向量(R.V.)间的协方差矩阵,其对角线上的元素分别是单个行向量(R.V.)的方差。所以如果初始数据[[0, 2], [1, 1], [2, 0]]是观测值要先转置再求协方差!
3. 矩阵的协方差矩阵的计算等价于单独将不同R.V.分量拿出来作为多个参数输入到cov函数中的协方差。from: http://blog.csdn.net/pipisorry/article/details/48770785
ref:numpy-ref-1.8.1 : 3.30 Statistics p1256