Quantcast
Channel: Data Science, Analytics and Big Data discussions - Latest topics
Viewing all articles
Browse latest Browse all 4448

One Hot encoding in PCA

$
0
0

@grasso wrote:

Hi, I am following up on an existing thread opened last 2015 with a new question in 2018 that somehow seemed to be left unanswered: Error : cannot rescale a constant/zero column to unit variance. Basically I am trying to convert categorical variables using one hot encoding and then feeding all the predictors (as.numeric) into prcomp() function but got the error: “error in prcomp.default(training_setx[-19], center = T, scale. = T) : cannot rescale a constant/zero column to unit variance”. I know the issue is with columns having constant 0 but that is precisely what one hot encoding does, so how can I overcome this issue to apply pca? I tried scaling the variable after one hot encoding but still received the same error. This is a sample of my script:
My_Data$My_variable = to_categorical(as.numeric(My_Data$My_variable)) #works fine
prcomp(My_Data, center=T, scale.=T) # RETURNS THE ERROR!
Also a question I have, is it correct to apply one hot encoding to categorical predictors in this case or would just suffice turning them in numeric? Thanks very much and hope to be hearing from you…

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4448

Trending Articles