PCA
import numpy as np
import matplotlib.pyplot as plt
from sklearn.decomposition import PCA
# X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
X = np.array([[1, 0.44,0.29,.33],
[.44, 1,.35,.32],
[.29, .35,1,.60],
[.33, .32,.60,1]])
print('打印x:\n{}'.format(X))
print("\n\n\n")
a, b = np.linalg.eig(X)
print('打印特征值a:\n{}'.format(a))
print('打印特征向量b:\n{}'.format(b))
print("\n\n\n")
# pca = PCA(n_components=2)
# newX = pca.fit_transform(X)
print(X)
# print(newX)
# print(pca.explained_variance_ratio_)
# pca = PCA(n_components=2)
pca = PCA()
newX = pca.fit_transform(X)
print('打印newX:\n{}'.format(newX))
# print(newX)
print(pca.explained_variance_ratio_)
plt.scatter(X[:, 0], X[:, 1], marker='o')
plt.scatter(newX[:, 0], newX[:, 0] * 0, color='r')
plt.show()
posted on 2019-07-23 11:24 Indian_Mysore 阅读(110) 评论(0) 编辑 收藏 举报