File tree Expand file tree Collapse file tree 1 file changed +3
-2
lines changed Expand file tree Collapse file tree 1 file changed +3
-2
lines changed Original file line number Diff line number Diff line change @@ -1008,21 +1008,22 @@ from sklearn.preprocessing import StandardScaler
1008
1008
x_train = scaler.transform(X)
1009
1009
```
1010
1010
- 使用PCA模型拟合数据,并降维
1011
+ - ` n_components ` 对应要将的维度
1011
1012
```
1012
1013
'''拟合数据'''
1013
1014
K=1 # 要降的维度
1014
1015
model = pca.PCA(n_components=K).fit(x_train) # 拟合数据,n_components定义要降的维度
1015
1016
Z = model.transform(x_train) # transform就会执行降维操作
1016
1017
```
1017
- - ` n_components ` 对应要将的维度
1018
1018
1019
1019
- 数据恢复
1020
+ - ` model.components_ ` 会得到降维使用的` U ` 矩阵
1020
1021
```
1021
1022
'''数据恢复并作图'''
1022
1023
Ureduce = model.components_ # 得到降维用的Ureduce
1023
1024
x_rec = np.dot(Z,Ureduce) # 数据恢复
1024
1025
```
1025
- - ` model.components_ ` 会得到降维使用的 ` U ` 矩阵
1026
+
1026
1027
1027
1028
1028
1029
---------------------------------------------------------------
You can’t perform that action at this time.
0 commit comments