首页 > 解决方案 > 使用 r 的块模型

问题描述

我正在尝试使用库块模型对一些生物数据进行分类。我得到了最好的数据模型(6 类)。问题是我如何获得每个数据的标签(标签向量)。这是我的代码(垫子是 132*132 数组):

my_model <- BM_poisson("SBM_sym",mat)
my_model$estimate()
which.max(my_model$ICL)
my_model$model_parameters[6]
my_model$plot_obs_pred(6)

谢谢

标签: rclassification

解决方案


这就是我解决问题的方法:

library("network")
library("ramify")
mynet <- as.network(mat)
my_model <- BM_bernoulli("SBM",mat)
my_model$estimate()
#K ist most probable number of classes
K<-which.max(my_model$ICL)
#argmax of Z is the most probable classmemebership
classmembership <-argmax(my_model$memberships[[K]]$Z)
#set classmembership as attribute for plotting
network::set.vertex.attribute(mynet, "Class", classmembership)

推荐阅读