(train)
return graph
把输入数据转化为以字典表示的无向图
把输入数据转化为以字典表示的无向图
把输入数据转化为以字典表示的无向图
def gen_graph(train):
    """
    把输入数据转化为以字典表示的无向图
    """ 
    data = train[train['label']==1][['q1','q2']]
    graph = {}
    for i in range(len(data)):
        if data.iloc[i,0] not in graph.keys():
            graph[data.iloc[i,0]] = set([data.iloc[i,1]])
        else:
            graph[data.iloc[i,0]].add(data.iloc[i,1])
    
        if data.iloc[i,1] not in graph.keys():
            graph[data.iloc[i,1]] = set([data.iloc[i,0]])
        else:
            graph[data.iloc[i,1]].add(data.iloc[i,0])
    
    return graph
def gen_graph ( train ) : data = train [ train [ 'label' ] == 1 ] [ [ 'q1' , 'q2' ] ] graph = { } for i in range ( len ( data ) ) : if data . iloc [ i , 0 ] not in graph . keys ( ) : graph [ data . iloc [ i , 0 ] ] = set ( [ data . iloc [ i , 1 ] ] ) else : graph [ data . iloc [ i , 0 ] ] . add ( data . iloc [ i , 1 ] ) if data . iloc [ i , 1 ] not in graph . keys ( ) : graph [ data . iloc [ i , 1 ] ] = set ( [ data . iloc [ i , 0 ] ] ) else : graph [ data . iloc [ i , 1 ] ] . add ( data . iloc [ i , 0 ] ) return graph