def loadData(): return [[1,1,1,0,0], [2,2,2,0,0], [1,1,1,0,0], [5,5,5,0,0], [1,1,0,2,2], [0,0,0,3,3], [0,0,0,1,1]] data = mat(loadData()) print(np.cov(data.T)) ''' [[ 2.95238095 2.95238095 3.02380952 -1.0952381 -1.0952381 ] [ 2.95238095 2.95238095 3.02380952 -1.0952381 -1.0952381 ] [ 3.02380952 3.02380952 3.23809524 -1.28571429 -1.28571429] [-1.0952381 -1.0952381 -1.28571429 1.47619048 1.47619048] [-1.0952381 -1.0952381 -1.28571429 1.47619048 1.47619048]] ''' print(corrcoef(data,rowvar = 0)) ''' [[ 1. 1. 0.97796525 -0.52462761 -0.52462761] [ 1. 1. 0.97796525 -0.52462761 -0.52462761] [ 0.97796525 0.97796525 1. -0.58806924 -0.58806924] [-0.52462761 -0.52462761 -0.58806924 1. 1. ] [-0.52462761 -0.52462761 -0.58806924 1. 1. ]] '''
对于数据的协方差表示的是不同特征之间的相关性