Skip to content

Commit ce045fd

Browse files
committed
📝 使用scikit-learn 中的PCA实现降维
1 parent 2a23263 commit ce045fd

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

readme.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,21 +1008,22 @@ from sklearn.preprocessing import StandardScaler
10081008
x_train = scaler.transform(X)
10091009
```
10101010
- 使用PCA模型拟合数据,并降维
1011+
- `n_components`对应要将的维度
10111012
```
10121013
'''拟合数据'''
10131014
K=1 # 要降的维度
10141015
model = pca.PCA(n_components=K).fit(x_train) # 拟合数据,n_components定义要降的维度
10151016
Z = model.transform(x_train) # transform就会执行降维操作
10161017
```
1017-
- `n_components`对应要将的维度
10181018

10191019
- 数据恢复
1020+
- `model.components_`会得到降维使用的`U`矩阵
10201021
```
10211022
'''数据恢复并作图'''
10221023
Ureduce = model.components_ # 得到降维用的Ureduce
10231024
x_rec = np.dot(Z,Ureduce) # 数据恢复
10241025
```
1025-
- `model.components_`会得到降维使用的`U`矩阵
1026+
10261027

10271028

10281029
---------------------------------------------------------------

0 commit comments

Comments
 (0)