首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于图的二部图的社区发现

基于图的二部图的社区发现
EN

Stack Overflow用户
提问于 2014-05-09 04:39:34
回答 1查看 1.6K关注 0票数 1

我有包含1000个版本的二部列表(帖子,单词类别),并希望使用快速且贪婪的算法进行社区检测,但我不确定是否必须在二部图或二部投影上运行它。

我的两部分列表如下所示:

代码语言:javascript
复制
   post word
1   66  2
2   312 1
3   432 7
4   433 7
5   434 1
6   435 5
7   436 1
8   437 4

当我在没有投影的情况下运行它时,我在第二步中遇到了集群问题:

代码语言:javascript
复制
### Load bipartie list and create graph ###
bipartite_list <- read.csv("bipartite_list_tnf.csv", header = TRUE, sep = ";")
bipartite_graph <- graph.incidence(bipartite_list)
g<-bipartite_graph
fc <- fastgreedy.community(g) ## communities / clusters
set.seed(123)
l <- layout.fruchterman.reingold(g, niter=1000, coolexp=0.5) ## layout
membership(fc)
# 2. checking who is in each cluster
cl <- data.frame(name = fc$post, cluster = fc$membership, stringsAsFactors=F)
cl <- cl[order(cl$cluster),]
cl[cl$cluster==1,]

# 3. preparing data for plot
d <- data.frame(l); names(d) <- c("x", "y")
d$cluster <- factor(fc$membership)

# 4. plot with only nodes, colored by cluster
p <- ggplot(d, aes(x=x, y=y, color=cluster))
pq <- p + geom_point()
pq

也许我得在投影仪上做公社检测?但我总是会失败,因为投影不是图形对象:

代码语言:javascript
复制
bipartite_graph <- graph.incidence(bipartite_list)
#projection (both directions)
projection_word_post <- bipartite.projection(bipartite_graph)
fc <- fastgreedy.community(projection_word_post)
Fehler in fastgreedy.community(projection_word_post) : Not a graph object

如果能帮上忙我会很高兴!

EN

回答 1

Stack Overflow用户

发布于 2016-08-04 05:38:12

在不使用投影的情况下运行时,问题出在:

代码语言:javascript
复制
bipartite_graph <- graph.incidence(bipartite_list)

在应用到graph.incidence()函数之前,您需要重塑'bipartite_list‘。使用下面的命令

代码语言:javascript
复制
tab <- table(bipartite_list)

剩下的步骤都是一样的

代码语言:javascript
复制
g <- graph.incidence(tab,mode=c("all"))
fc <- fastgreedy.community(g)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23552060

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档