def plotPrincipalComponents(principal1, principal2, X, y, classNames):
C = len(classNames)
Y = X - np.ones((len(X),1))*X.mean(0)
U,S,V = linalg.svd(Y,full_matrices=False)
V = mat(V).T
Z = Y * V
# Plot PCA of the data
f = figure()
f.hold()
title('Data projected onto Principal Components')
for c in range(C):
class_mask = y.A.ravel()==c
plot(Z[class_mask,principal1], Z[class_mask,principal2], 'o')
legend([convertToWord(i) for i in classNames])
xlabel('PC{0}'.format(principal1+1))
ylabel('PC{0}'.format(principal2+1))
show()
# Gets the direction of a certain principal component
project1.py 文件源码
python
阅读 24
收藏 0
点赞 0
评论 0
评论列表
文章目录