Utils¶
Clusters¶
Functions to manipulate and sort clusters
- cluster_sort(clusters, final_labels=None)[source]¶
Return array of cluster labels sorted in order of appearance, with clusters unchanged
Example
>>> clusters = np.array([2, 2, 2, 3, 3, 1, 1, 1]) >>> cluster_sort(clusters) [ 1 1 1 2 2 3 3 3 ]
- rand_index_over_methods_and_sizes(valid_cluster_sets, reference_method='ward')[source]¶
Compute Rand Index to compare any method to a reference method, for all combinations of methods and number of clusters
- Parameters
valid_cluster_sets (list) –
reference_method (str) –
- Returns
rand_scores – Array of dimension (n_sizes, n_methods) with rand index scores
- Return type
ndarray
Graphs¶
Utility functions for static graphs
- create_graph_from_interactions(filename, sheet, source, target)[source]¶
Create a networkx.Graph from an excel sheet describing edges
- Parameters
filename (str) – Path to the excel file
sheet (str) – Name of the sheet within the excel file
source (str) – Name of the column containing the source nodes
target (str) – Name of the column containing the target nodes
- Returns
graph
- Return type
networkx.Graph
Paths¶
Functions to deal with system paths
- slugify(text, keep_characters=None)[source]¶
Turn any text into a string that can be used in a filename
- Parameters
text (str) – text to slugify
keep_characters (list of str) – characters in this iterable will be kept in the final string. Defaults to [‘_’]. Any other non-alphanumeric characters will be removed.
- Returns
slug
- Return type
str