Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing Percentage of Variance Explained for PCA #193

Closed
jeromefroe opened this issue Jul 27, 2015 · 4 comments
Closed

Accessing Percentage of Variance Explained for PCA #193

jeromefroe opened this issue Jul 27, 2015 · 4 comments

Comments

@jeromefroe
Copy link

Hello,

I wanted to suggest adding an element to the preProcess list so that the user can easily access the percent of variance explained for each principal component. For example, I can find the percent variance explained from prcomp by:

PCA.1 <- prcomp(iris[,1:4],
center = TRUE,
scale. = TRUE)

PCA.1$sdev / sum(PCA.1$sdev) # get percent variance explained for each principal component

There doesn't seem to be an equivalent method to do this using the result from a preProcess call such as:

library(caret)
pcaTransform = preProcess(iris[,1:4], thresh = 0.9999,
method=c("center", "scale", "pca"))
PCA.2 = predict(pcaTransform, iris[,1:4])

Thanks!

@topepo
Copy link
Owner

topepo commented Jul 27, 2015

You and me both! The news file on the latest CRAN version has "When PCA pre-processing is conducted, the variance trace is saved in an object called trace."

For example:

> library(caret)
> library(earth)
> 
> set.seed(135)
> tr_dat <- twoClassSim(100)
> 
> set.seed(417)
> mod <- train(Class ~ ., data = tr_dat, method = "knn",
+              preProc = c("center", "scale", "pca"))
> head(mod$preProcess$trace)
[1] 0.1208276 0.2182919 0.3141637 0.4055406 0.4818360 0.5559183
> min(which(mod$preProcess$trace > .95))
[1] 14

@topepo topepo closed this as completed Jul 27, 2015
@jeromefroe
Copy link
Author

Whoops. Must have missed this in the latest version. Thanks! This is a very helpful feature!

@hendrikweisser
Copy link
Contributor

I would appreciate this functionality as well, but it looks like the trace object was removed in commit 399b973. Was this intentional or an oversight?

@kmacierzanka
Copy link

I would appreciate this functionality as well, but it looks like the trace object was removed in commit 399b973. Was this intentional or an oversight?

I really hope this is brought back!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants