How to use PCA technique to build classification model

r
classification
pca

#1

I am building a classification model .I want to to know that technique like PCA can be used to build a classification model like C5.0 decision tree in R.I have created the components and I want to know how the result of PCA can be used to train and test the model.

my.prc <- prcomp(train[,-1], center=TRUE, scale=TRUE)
How to use result of PCA in C5.0 decision tree


#2

@hinduja1234- as you have calculated the component then you can axis their rotation of each component
then train the data and test data with calculated rotated value

components<-a # the value of component calculated by PCA
Data<-pca$x[,1:component] #access of rotated value combined train and test data.

Hope this helps!
Regards,
harry


#3

Hi Hinduja,

my.pc is now your model in a way made of multiple what we call principal components. Now you have to take a decision how many principal component or in other words how variance do I want to keep??

it looks like this

newpac <-predict(my.prc, newdata=testdata$mydata)

and we go now you the principal component for you testdata

newpac[,1] …newpac[,2] etc they are you new variables

so if you keep testdata you remove them and add new pac[,1] , new pac[,2] etc…,
rbind(testdata, var1=new.pac[,1] …, ) type

which variance ?? you have to square the individual standard deviation and divided by sum of all the standard deviations which give (we do this on the train data)

my.prc $sdev[1]^2/sum(my.prc $sdev^2) this will be the variance you explain by using the first principal component ,

you can continue with sum(my.prc $sdev[1]^2+my.prc $sdev[2]^2… )/ sum(my.prc $sdev^2) until you reach the variance you want usually by 3 or 4 you should be at 90% or more

Good luck