sospcat.spatial

Module to define the spatial based partitioning

get_groups(node_locations, nbr_clusters, return_form='membership', random_state=None, **kwargs)[source]

Perform k-means clustering on the provided node locations.

Parameters
  • node_locations (dict) – Specify for each node (key) its position (value) in the form of a tuple, (x, y).

  • nbr_clusters (int) – The number of clusters to find.

  • return_form (str (default='membership')) –

    Determines the format of how the social group structure should be returned. Options are:

    • 'membership': A dict returning for each node (key) the group it belongs to (value).

    • 'memberlists': Dictionary with a list of members (value) for each group (key).

  • random_state (int, RandomState instance, default=None) – Determines random number generation for centroid initialization. Use an int to make the randomness deterministic.

  • **kwargs – All keyword arguments forwarded to sklearn.cluster.KMeans.

Returns

Depending on what was chosen for the return_form attribute, either the membership dict, i.e.:

{
    node_id: group_id,
    ...
}

or the memberlist dict, i.e.:

{
    group_id: [node1_id, node2_id, ...],
    ...
}

(value) is returned.

Return type

dict