无法从具有网状结构的 pyclustering 对象获得结果
Can't get result from the pyclustering object with reticulate
我想用 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()
但是 returns NULL
.
请问,哪里有问题?
我认为问题出在 pyclustering
库的使用上,而不是 reticulate
或 R
。如 README example 中所述,您需要 运行 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
此外,请注意您需要明确指定整数,其中预期
我想用 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()
但是 returns NULL
.
请问,哪里有问题?
我认为问题出在 pyclustering
库的使用上,而不是 reticulate
或 R
。如 README example 中所述,您需要 运行 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
此外,请注意您需要明确指定整数,其中预期