def read_nodes_from_training(file_name):
    """
    Returns a list of all the nodes in the graph
    """
    node_set = set()

    for nodes in utilities.edges_generator(file_name):
        for node in nodes:
            node_set.add(node)

    return list(node_set)
Ejemplo n.º 2
0
def read_nodes_from_training(file_name):
    """
    Returns a list of all the nodes in the graph
    """
    node_set = set()

    for nodes in utilities.edges_generator(file_name):
        for node in nodes:
            node_set.add(node)

    return list(node_set)
def get_top_k_nodes(file_name, k):
    """
    Returns a list of the top k most followed nodes
    """
    node_followers = {}

    for nodes in utilities.edges_generator(file_name):
        if nodes[1] not in node_followers:
            node_followers[nodes[1]] = 0
        node_followers[nodes[1]] += 1

    return sorted(node_followers.keys(), 
                  key=lambda n: node_followers[n], 
                  reverse = True)[:k]
def get_top_k_nodes(file_name, k):
    """
    Returns a list of the top k most followed nodes
    """
    node_followers = {}

    for nodes in utilities.edges_generator(file_name):
        if nodes[1] not in node_followers:
            node_followers[nodes[1]] = 0
        node_followers[nodes[1]] += 1

    return sorted(node_followers.keys(),
                  key=lambda n: node_followers[n],
                  reverse=True)[:k]