Skip to content

Commit b094480

Browse files
committed
📝 PCA主成分分析,数据降维
1 parent 324542b commit b094480

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

readme.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -950,13 +950,12 @@ def runKMeans(X,initial_centroids,max_iters,plot_process):
950950
- ![$${X_{approx}} = {(U_{reduce}^{ - 1})^{ - 1}}Z = {U_{reduce}}Z$$](http://latex.codecogs.com/gif.latex?%5Cfn_cm%20%24%24%7BX_%7Bapprox%7D%7D%20%3D%20%7B%28U_%7Breduce%7D%5E%7B%20-%201%7D%29%5E%7B%20-%201%7D%7DZ%20%3D%20%7BU_%7Breduce%7D%7DZ%24%24)
951951
- 实现代码:
952952
```
953-
# 映射数据
954-
def projectData(X_norm,U,K):
955-
Z = np.zeros((X_norm.shape[0],K))
956-
957-
U_reduce = U[:,0:K] # 取前K个
958-
Z = np.dot(X_norm,U_reduce)
959-
return Z
953+
# 恢复数据
954+
def recoverData(Z,U,K):
955+
X_rec = np.zeros((Z.shape[0],U.shape[0]))
956+
U_recude = U[:,0:K]
957+
X_rec = np.dot(Z,np.transpose(U_recude)) # 还原数据(近似)
958+
return X_rec
960959
```
961960

962961
### 6、主成分个数的选择(即要降的维度)

0 commit comments

Comments
 (0)