2017-09-11 2 views
0
for i in Train.index : 


    preds = nx.jaccard_coefficient(G, ebunch = (Train['source_node'][i], Train['destination_node'][i])) 
    for u,v,p in preds: 
     print('(%d, %d) -> %.8f' % (u, v, p)) 

TypeError         Traceback (most recent call last) 
<ipython-input-23-95e128c1b501> in <module>() 
     3 
     4  preds = nx.jaccard_coefficient(G, ebunch = (Train['source_node'][i], Train['destination_node'][i])) 
----> 5  for u,v,p in preds: 
     6   print('(%d, %d) -> %.8f' % (u, v, p)) 

C:\ProgramData\Anaconda3\lib\site-packages\networkx\algorithms\link_prediction.py in <genexpr>(.0) 
    136    return len(cnbors)/union_size 
    137 
--> 138  return ((u, v, predict(u, v)) for u, v in ebunch) 
    139 
    140 

TypeError: 'numpy.int64' object is not iterable 
+1

있는 개체의 어떤 종류의'기차 [ 'source_node'] [I]'와'기차 [ 'destination_node'] [I]'예를 들어, 여기에 내가 하나의 튜플을 포함하는 목록을 수 ebunch 설정 ? –

답변

0

인수 ebunch는 튜플의 반복 가능해야합니다 반복자되지 않습니다. Train['source_node'][i]Train['destination_node'][i]이 무엇인지 알 수있는 충분한 코드가 표시되지 않았지만 오류 메시지를 기반으로 해당 코드가 numpy.int64 인 것으로 의심됩니다. 이 경우 ebunch 인수에서 이러한 한 단계 더 자세하게 중첩해야합니다.

preds = nx.jaccard_coefficient(G, ebunch = [(Train['source_node'][i], Train['destination_node'][i])])