简体   繁体   中英

how PCA fit transform on test set

I am using the from sklearn.decomposition import PCA library, IncrementalPCA to reduce the dimensionality of my problem as follows:

training_data = [...] 
training_target = [...]
test_data = [...]
test_target = [...] 
ipca = IncrementalPCA(n_components, batch_size)
new_training_data = ipca.fit_transform(training_data)

To run the tests with a given classifier, I need to fit the test set with the information obtained in the training set (something like eigenvalues and eigenvectors), to reduce the same size of the new training set. But how can I do this with this library (or some other), since the ipca.fit_transform(data) does not return anything to me like eg eigpairs or some value to resize the dimension of the test set?

The transform is internal to the IncrementalPCA object after you call fit or fit_transform . When you call icpa.fit_transform , you are telling it to determine the principal components transform for the given data and to also apply that transform to the data. To then transform another data set, just use the transform method of the trained IncrementalPCA object:

new_test_data = ipca.transform(test_data)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM