diff --git a/盘荣博/数据可视化/week1.py b/盘荣博/数据可视化/week1.py index 74a1462..0212c66 100644 --- a/盘荣博/数据可视化/week1.py +++ b/盘荣博/数据可视化/week1.py @@ -1,5 +1,11 @@ import pandas as pd +<<<<<<< HEAD +import numpy as np from scipy.stats import zscore +from sklearn.decomposition import PCA +======= +from scipy.stats import zscore +>>>>>>> remotes/origin/盘荣博 import matplotlib.pyplot as plt from matplotlib.pyplot import ylabel df = pd.read_excel("棉花产量论文作业的数据.xlsx") @@ -38,5 +44,27 @@ plt.scatter(data2[:,:1],data2[:,1:2],c='g') plt.xlabel('压缩到0~1') print(data==data1) +<<<<<<< HEAD +# plt.savefig("shuju.jpg",dpi=2000) +# plt.show() +md= PCA().fit(data) +cf = np.cov(data.T)#求协方差矩阵 +print(cf) +c, d= np.linalg.eig(cf) +print("特征值:\n",c) +print(md.explained_variance_) +e=c/c.sum() +# for _ in range(len(e)): +# if(_!=0): +# e[_]+=e[_-1] +print('贡献率:') +print(e) +print(md.explained_variance_ratio_) +print('特征向量:') +print(d.T) +print(md.components_) +print(md.components_-d.T<=0.1) +======= plt.savefig("shuju.jpg",dpi=2000) -plt.show() \ No newline at end of file +plt.show() +>>>>>>> remotes/origin/盘荣博