Home:ALL Converter>Project training data onto PCA R

Project training data onto PCA R

Ask Time:2022-02-12T04:25:41         Author:IDK

Json Formatter

I'm a total beginner in ML, R, you name it and I'm using FactoMineR's PCA function on my training set to find the principal components of my data.

res_pca <- PCA(training, scale.unit=TRUE, graph=FALSE)

Now I have to project my training data onto the space spanned by the vectors found by PCA. How do I do that?

This is what I've tried:

# get_pca_var is from the factoextra package
var <- get_pca_var(res_pca)
# training_no_target is just the training dataset without the target variable, which is a factor 
train_pca <- as.matrix(training_no_target) %*% var$coord
train_pca <- data.frame(train_pca)

I think train_pca should now contain the final dataset onto which training my models... is this right?

Author:IDK,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/71086175/project-training-data-onto-pca-r
yy