【发布时间】:2016-01-24 06:03:05
【问题描述】:
我正在尝试使用以下代码运行 igraph 的快速贪婪社区检测算法:
G = Graph()
L = []
V = []
for row in cr:
try:
l = []
source = int((row[0]).strip())
target = int((row[1]).strip())
weight = int((row[2]).strip())
l.append(source)
l.append(target)
if l not in L:
L.append(l)
if source not in V:
V.append(source)
if target not in V:
V.append(target)
except ValueError:
print "Value Error"
continue
if weight == 1:
continue
G.add_vertices(max(V))
G.add_edges(L)
cl = G.community_fastgreedy(weights=weight).as_clustering(10);
但这是我得到的错误: igraph._igraph.InternalError:type_indexededgelist.c:272 处的错误:无法添加边,顶点 ID 无效
我发现了这个:Cannot add edges, Invalid vertex ID in IGraph 所以我尝试添加所有顶点,然后添加所有边,但仍然出现错误。
上面的代码是否与以下代码相同:
tupleMapping = []
for row in cr:
if int(row[2]) < 10:
continue
l = [row[0], row[1], row[2]]
tupleMapping.append(tuple(l))
g = Graph.TupleList(tupleMapping)
cl = g.community_fastgreedy().as_clustering(20)
我不必明确地说 G.community_fastgreedy(weights=weight) 对吧?
我还有另一个问题;当我尝试通过以下方式添加更多集群时:
cl = g.community_fastgreedy().as_clustering(10)
cl = g.community_fastgreedy().as_clustering(20)
我得到两个大集群,其余集群由一个元素组成。当我尝试将集群大小设置为 5/10/20 时会发生这种情况,有什么方法可以让集群更加平均分配吗?我的数据集需要 2 个以上的集群。
这是我试图从 csv 文件中读取的数据的一个小 sn-p,以便我可以生成一个图表,然后运行社区检测算法: 202,580,11 87,153,7 227,459,6 263,524,11
谢谢。
【问题讨论】:
标签: python-2.7 cluster-analysis igraph hierarchical-clustering