cdlib.evaluation.sample_expected_sim¶
- cdlib.evaluation.sample_expected_sim(first_partition: object, second_partition: object, measure: str = 'jaccard_index', random_model: str = 'perm', n_samples: int = 1, keep_samples: bool = False) MatchingResult¶
This function calculates the expected Similarity for all pair-wise comparisons between Clusterings drawn from one of six random models.
Note
Clustering 2 is considered the gold-standard clustering for one-sided expectations
- Parameters:
first_partition – NodeClustering object
second_partition – NodeClustering object
measure – The similarity measure to evaluate. Must be one of [ecs, jaccard_index, rand_index, fowlkes_mallows_index, classification_error, czekanowski_index, dice_index, sorensen_index, rogers_tanimoto_index, southwood_index, mi, rmi, vi, geometric_accuracy, overlap_quality, sample_expected_sim]
random_model –
The random model to use:
- ’all’uniform distribution over the set of all clusterings of
n_elements
- ’all1’one-sided selection from the uniform distribution over the set
of all clusterings of n_elements
- ’num’uniform distribution over the set of all clusterings of
n_elements in n_clusters
- ’num1’one-sided selection from the uniform distribution over the set
of all clusterings of n_elements in n_clusters
’perm’ : the permutation model for a fixed cluster size sequence
- ’perm1’one-sided selection from the permutation model for a fixed
cluster size sequence, same as ‘perm’
n_samples – The number of random Clusterings sampled to determine the expected similarity.
keep_samples – If True, returns the Similarity samples themselves, otherwise return their mean.
- Returns:
MatchingResult object
- Example:
>>> from cdlib import evaluation, algorithms >>> import networkx as nx >>> g = nx.karate_club_graph() >>> louvain_communities = algorithms.louvain(g) >>> leiden_communities = algorithms.leiden(g) >>> evaluation.sample_expected_sim(louvain_communities,leiden_communities)
Note
The function requires the clusim library to be installed. You can install it via pip: pip install clusim