Seaborn不绘制矩阵

时间:2018-10-29 11:40:32

标签: python matplotlib seaborn pca

我正在尝试绘制特征值矩阵,以便生成PCA图,但是我所得到的只是一个空图和下面的错误消息。

代码如下:

#eigmatrix

matrix_w = np.hstack((eig_pairs[0][1].reshape(17,1),
                      eig_pairs[1][1].reshape(17,1)))
print('Matrix W:\n', matrix_w)

Matrix W:
 [[ 0.29094485  0.16905486]
 [ 0.22524378  0.42849434]
 [-0.31034257  0.00325389]
 [-0.07122103 -0.17919345]
 [-0.27987488  0.25877484]
 [-0.27134905  0.12025245]
 [ 0.24237126  0.38559497]
 [-0.26636628  0.28480759]
 [ 0.24128234  0.41261663]
 [-0.28932899  0.25743508]
 [-0.25070043  0.23997005]
 [ 0.21677115 -0.00142499]
 [ 0.11280528 -0.16767718]
 [ 0.07118854  0.04231505]
 [ 0.23664841  0.1107044 ]
 [ 0.27095368  0.14662388]
 [-0.2873956   0.29444027]]

#plotting PCA
Y = X_std.dot(matrix_w)

with plt.style.context('seaborn-whitegrid'):
    plt.figure(figsize=(6, 4))
    plt.show()
    for lab, col in zip(('Lumbar_P2-3', 'Cervical_P2-3', 'Lumbar_P6-7','Cervical_P6-7','Lumbar_P15+'),
                        ('blue', 'red', 'green', 'black', 'grey')):
        plt.scatter(Y[y==lab, 0],
                    Y[y==lab, 1],
                    label=lab,
                    c=col)
    plt.xlabel('Principal Component 1')
    plt.ylabel('Principal Component 2')
    plt.legend(loc='lower center')
    plt.tight_layout()
    plt.show()

enter image description here

C:\ProgramData\Anaconda3\lib\site-packages\ipykernel_launcher.py:8: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison

C:\ProgramData\Anaconda3\lib\site-packages\ipykernel_launcher.py:9: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
  if __name__ == '__main__':

0 个答案:

没有答案