Skip to content

Commit 6860053

Browse files
committed
📝 PCA主成分分析,数据降维
1 parent 09781cd commit 6860053

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

PCA/PCA.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def projectData(X_norm,U,K):
102102
def drawline(plt,p1,p2,line_type):
103103
plt.plot(np.array([p1[0],p2[0]]),np.array([p1[1],p2[1]]),line_type)
104104

105+
105106

106107
# 恢复数据
107108
def recoverData(Z,U,K):

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -949,14 +949,14 @@ def runKMeans(X,initial_centroids,max_iters,plot_process):
949949
- 又因为`Ureduce`为正定矩阵,【正定矩阵满足:![$$A{A^T} = {A^T}A = E$$](http://latex.codecogs.com/gif.latex?%5Cfn_cm%20%24%24A%7BA%5ET%7D%20%3D%20%7BA%5ET%7DA%20%3D%20E%24%24),所以:![$${A^{ - 1}} = {A^T}$$](http://latex.codecogs.com/gif.latex?%5Cfn_cm%20%24%24%7BA%5E%7B%20-%201%7D%7D%20%3D%20%7BA%5ET%7D%24%24)】,所以这里:
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
- 实现代码:
952-
```
952+
```
953953
# 恢复数据
954954
def recoverData(Z,U,K):
955955
X_rec = np.zeros((Z.shape[0],U.shape[0]))
956956
U_recude = U[:,0:K]
957957
X_rec = np.dot(Z,np.transpose(U_recude)) # 还原数据(近似)
958958
return X_rec
959-
```
959+
```
960960

961961
### 6、主成分个数的选择(即要降的维度)
962962
- 如何选择

0 commit comments

Comments
 (0)