1.PCA
from sklearn.decomposition import RandomizedPCA # 100维度 n_components = 100 pca = RandomizedPCA(n_components=n_components, whiten=True).fit(x_train) # 将降维的再调回去 eigenfaces = pca.components_.reshape((n_components, h, w)) # 特征提取 x_train_pca = pca.transform(x_train) x_test_pca = pca.transform(x_test)
2.标准化
from sklearn import preprocessing import numpy as np X = np.array([[ 1., -1., 2.],[ 2., 0., 0.],[ 0., 1., -1.]]) scaler= preprocessing.MinMaxScaler(feature_range=(-1, 1)).fit(X) X_scaled = scaler.transform(X) # 将标准化的数据转化为原数据 X1=scaler.inverse_transform(X_scaled)