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)