koalaverse / homlr

Supplementary material for Hands-On Machine Learning with R, an applied book covering the fundamentals of machine learning with R.
https://koalaverse.github.io/homlr
Creative Commons Attribution Share Alike 4.0 International
226 stars 88 forks source link

Principal Component Analysis code error #58

Open vishnugunneri opened 2 years ago

vishnugunneri commented 2 years ago

The following code:isn't running-

How many PCs required to explain at least 75% of total variability

min(which(ve$CVE >= 0.75))

[1] 27

Might be an issue with variable 've' because there is none Hands on ML error

bradleyboehmke commented 2 years ago

Good catch @vishnugunneri , there is a hidden code chunk that computes ve via:

ve <- data.frame(
  PC  = my_pca@model$importance %>% names(),
  PVE = my_pca@model$importance %>% .[2,] %>% unlist(),
  CVE = my_pca@model$importance %>% .[3,] %>% unlist()
)