Skip to content

Commit

Permalink
don't use CENTROIDS in test
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilHvitfeldt committed Jun 17, 2024
1 parent 12fa3c9 commit 216aee3
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions tests/testthat/test-k_means_diagnostics.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
test_that("kmeans sse metrics work", {
set.seed(1234)
kmeans_fit_stats <- k_means(num_clusters = mtcars[1:3, ]) %>%
set_engine("stats", algorithm = "MacQueen") %>%
fit(~., mtcars)

# We don't use CENTROIDS argument becuase it breaks testing for different
# versions of ClusterR #186
kmeans_fit_ClusterR <- k_means(num_clusters = 3) %>%
set_engine("ClusterR", CENTROIDS = as.matrix(mtcars[1:3, ])) %>%
set_engine("ClusterR") %>%
fit(~., mtcars)

km_orig <- kmeans(mtcars, centers = mtcars[1:3, ], algorithm = "MacQueen")
km_orig_2 <- ClusterR::KMeans_rcpp(
data = mtcars,
clusters = 3,
CENTROIDS = as.matrix(mtcars[1:3, ])
clusters = 3
)

expect_equal(sse_within(kmeans_fit_stats)$wss,
Expand Down Expand Up @@ -92,7 +94,7 @@ test_that("kmeans sihouette metrics work", {
fit(~., mtcars)

kmeans_fit_ClusterR <- k_means(num_clusters = 3) %>%
set_engine("ClusterR", CENTROIDS = as.matrix(mtcars[1:3, ])) %>%
set_engine("ClusterR") %>%
fit(~., mtcars)

new_data <- mtcars[1:4, ]
Expand Down Expand Up @@ -124,7 +126,7 @@ test_that("kmeans sihouette metrics work with new data", {
fit(~., mtcars)

kmeans_fit_ClusterR <- k_means(num_clusters = 3) %>%
set_engine("ClusterR", CENTROIDS = as.matrix(mtcars[1:3, ])) %>%
set_engine("ClusterR") %>%
fit(~., mtcars)

new_data <- mtcars[1:4, ]
Expand Down

0 comments on commit 216aee3

Please sign in to comment.