PCA

PCA

The PCA package from sklearn can be used.

Create the pca package and save it.

from sklearn.decomposition import PCA
from sklearn.externals import joblib
import numpy as np

x = np.arange(10).reshape(2, 5)
pca1 = PCA(n_components=2)
x_train = pca1.fit_transform(x) # x_train是降维后的训练集
joblib.dump(pca1, 'pca.m') # 将模型保存到pca.m文件中

x_test1 = pca1.transform(x) # 将模型运用到新数据中,此处就用x做测试
print(x_test1)

pca2 = joblib.load('pca.m') # 读入模型pca.m
x_test2 = pca2.transform(x)
print(x_test2)

https://zhuanlan.zhihu.com/p/88857051

posted @ 2022-06-27 20:01  xiaoxuxli  阅读(8)  评论(0编辑  收藏  举报