def plot3DPrincipalComponents(X,y,classNames,prin1,prin2,prin3,attributeNames):
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
f = figure()
hold(True)
colors = ['blue', 'green']
ax = f.add_subplot(111, projection='3d')
for c in range(C):
class_mask = (y==c).A.ravel()
ax.scatter(Z[class_mask,prin1].A, Z[class_mask,prin2].A, Z[class_mask,prin3].A, c=colors[c])
ax.set_xlabel('PC{0}'.format(prin1+1))
ax.set_ylabel('PC{0}'.format(prin2+1))
ax.set_zlabel('PC{0}'.format(prin3+1))
title("3D plot of principal components")
legend(attributeNames)
#Using CHD as attribute
project1.py 文件源码
python
阅读 35
收藏 0
点赞 0
评论 0
评论列表
文章目录