Skip to content
New issue

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

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

Already on GitHub? # to your account

make sure PCA steps works with many variables #82

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# orbital (development version)

* Fixed bug where PCA steps didn't work if they were trained with more than 99 predictors. (#82)

# orbital 0.3.0

* `orbital()` has gained `type` argument to change prediction type. (#66)
Expand Down
2 changes: 1 addition & 1 deletion R/recipes-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ pca_helper <- function(rot, prefix, all_vars) {
}

pca_naming <- function(x, prefix) {
gsub(paste0(prefix, "0"), prefix, x)
gsub(paste0(prefix, "0+"), prefix, x)
}
19 changes: 19 additions & 0 deletions tests/testthat/test-step_pca.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ test_that("step_pca works with more than 9 PCs", {
expect_equal(res, exp)
})

test_that("step_pca works with more than 100 PCs", {
skip_if_not_installed("recipes")

data <- lapply(1:1000, function(x) sample(0:1, 100, TRUE))
names(data) <- paste0("V", 1:1000)
data <- dplyr::as_tibble(data)

rec <- recipes::recipe(~ ., data = data) %>%
recipes::step_pca(recipes::all_predictors()) %>%
recipes::prep()

exp <- recipes::bake(rec, new_data = data)

res <- dplyr::mutate(data, !!!orbital_inline(orbital(rec)))
res <- res[names(exp)]

expect_equal(res, exp)
})

test_that("step_pca only calculates what is sufficient", {
skip_if_not_installed("recipes")

Expand Down
Loading