3

我想用 Python ( pyclustering) 中的库对 R 中的一些数据进行聚类。我正在使用reticulate包来执行此操作:

library(reticulate)
# create some random array
np <- import("numpy", convert = FALSE)
dat <- np$random$rand(100,2)
# clustering with CURE
clus_cure <- import("pyclustering.cluster.cure")
clus_res <- clus_cure$cure(dat, 2)
clus_res$get_clusters()

但它返回NULL

请问哪里有问题?

4

1 回答 1

2

我认为问题在于使用pyclustering库而不是使用reticulateor R。如 README示例中所示,您需要process()在对象上运行函数<pyclustering.cluster.cure.cure>

library(reticulate)
# create some random array
np <- import("numpy", convert = FALSE)
dat <- np$random$rand(10L,2L)
# clustering with CURE
clus_cure <- import("pyclustering.cluster.cure")
clus_res <- clus_cure$cure(data = dat, number_cluster=2L)
clus_res$process()
print(clus_res$get_clusters())
#> [[1]]
#> [1] 2 3 8 0 1 7 4 9
#> 
#> [[2]]
#> [1] 5 6

另外,请注意,您需要在预期的地方显式指定整数

于 2018-05-18T10:09:52.967 回答