build¶
build contains functions to create networks
- nesta_ds_utils.networks.build.build_coocc(sequences: Union[List[list], List[array]], graph_type: str = 'networkx', directed: bool = False, as_adj: bool = False, use_node_weights: bool = False, edge_attributes: List = []) Union[Graph, csr_matrix] [source]¶
generates a co-occurence graph based on pairwise co-occurence of tokens.
- Parameters:
sequences (Union[List[list], List[np.array]]) – list of lists or list of numpy arrays containing tokens to use as nodes in the network.
graph_type (str, optional) – Python library to use for network generation. Currently only supports ‘networkx’ but future development should support ‘graph-tool’
directed (bool, optional) – parameter to indicate if edges should be directed. Defaults to False. If True, creates a symmetric graph.
as_adj (bool, optional) – parameter to indicate if network should be returned as an adjacency matrix rather than a Graph object.
use_node_weights (bool, optional) – parameter to indicate if node frequency should be added as a node attribute.
edge_attributes (List, optional) – parameter to specify any attributes to add to the edges of the network. Available options are ‘frequency’, ‘jaccard’, ‘association’, ‘cosine’, or ‘inclusion’. Defaults to []. Functions are based on van Eck and Waltman, 2009.
- Returns:
Returns networkx graph object. If directed=True returns nx.DiGraph, otherwise returns nx.Graph. if as_adj = True returns an adjacency matrix and set of nodes corresponding to rows/columns
- Return type:
nx.Graph