From 216aee36a3bdde53d9da96c802efad9428d93d9a Mon Sep 17 00:00:00 2001 From: Emil Hvitfeldt Date: Mon, 17 Jun 2024 09:39:12 -0700 Subject: [PATCH] don't use CENTROIDS in test --- tests/testthat/test-k_means_diagnostics.R | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/testthat/test-k_means_diagnostics.R b/tests/testthat/test-k_means_diagnostics.R index 1e0cc31b..98f355e0 100644 --- a/tests/testthat/test-k_means_diagnostics.R +++ b/tests/testthat/test-k_means_diagnostics.R @@ -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, @@ -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, ] @@ -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, ]