# PCA降维与线性判别分析--鲍鱼

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from sklearn.decomposition import PCA
data.columns = ['Sex', 'Length', 'Diameter', 'Height',
'Whole weight', 'Shucked weight', 'Viscera weight',
'Shell weight', 'Rings']
y = pd.DataFrame(data,columns=['Sex'])
X=data[['Length', 'Diameter', 'Height',
'Whole weight', 'Shucked weight', 'Viscera weight',
'Shell weight', 'Rings']]
X=np.array(X)                      #将数据储存于矩阵中
from sklearn.decomposition import PCA
pca = PCA(n_components=8)
pca.fit(X)
print("\n特征方差百分比:",pca.explained_variance_ratio_)



9.78633807e-05 4.55098674e-05 3.88842581e-05 1.37538404e-05]

#变量关系可视化平行坐标图
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
array = data.iloc[:,1:9].values
array1=data.iloc[:,1:8].values
plt.figure(figsize=(10,6))
for i in range(array.shape[0]):
point = array[i,:]
plt.plot(point)
plt.xticks(np.arange(8),('l','2','3','4','5','6','7','8'),fontsize = 14)
plt.show()

for i in range(array1.shape[0]):
point = array1[i,:]
plt.plot(point)
plt.xticks(np.arange(7),('l','2','3','4','5','6','7'),fontsize = 13)
plt.show()#画出的第八个与前面相差较大则删去第八

<

• 4
点赞
• 1
收藏
觉得还不错? 一键收藏
• 1
评论
04-01 1435
11-26 674
08-28 2103
11-11 821
09-13 545
09-12 1246
09-13 1642

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、付费专栏及课程。