Package: corankco
corankcocorankco(COnsensus RANKing COmputation) is a Python package dedicated to the aggregation of incomplete rankings with ties. Users can choose the Kemeny-Young method (exact algorithm and several heuristics available), the Copeland method, and in some cases, the Borda method. The formalism to handle ties and/or incompleteness is detailed in the preprint: P. Andrieu, S. Cohen-Boulakia, M. Couceiro, A. Denise, A. Pierrot.A Unifying Rank Aggregation Model to Suitably and Efficiently Aggregate Any Kind of Rankings. Available at SSRN:https://ssrn.com/abstract=4353494.As of our latest release, the API forcorankcois now stable and finalized.InstallationBefore installingcorankco, make sure your system meets the following requirements:Python >= 3.8For the usage of the exact algorithm on big datasets (with many elements to rank), the installation of IBM ILOG CPLEX Optimization Studio is recommended. A free academic version can be downloaded from theIBM website. After downloading, follow theinstructions to install CPLEX.README.mdTo installcorankcofrom PyPI, you can use pip:pip3installcorankcoDocumentationVisit ourofficial documentation.
For examples of use, you can jump directly to our [Usage section below]{#usage}.Contact/SupportFor any queries or support related to corankco, feel free to reach us atpierre.andrieu@lilo.org.ContributingWe welcome contributions tocorankco. If you'd like to contribute, feel free to fork the repository and submit your changes via a pull request.Licensecorankcois licensed under the GPL-2.0 License. You can read more about it in theLICENSE file.UpdatesNew in 7.2.0Several algorithms have been sped up.BioConsert heuristic no longer requires the C extension. As a consequence, corankco is now available for any platform.
Note that the computation time of BioConsert has been reduced due to major code improvements.Minor bug fix in BioConsert heuristic.Several tests addedExample usagefromtypingimportListimportcorankcoascrc# create a ranking from a list of setsranking1:crc.Ranking=crc.Ranking([{1},{2,3}])# or from a stringranking2:crc.Ranking=crc.Ranking.from_string("[{3, 1},{4}]")# also in this formatranking3:crc.Ranking=crc.Ranking.from_string("[[1], [5], [3], [2]]")# now, create a Dataset object. A Dataset is a list of rankingsdataset:crc.Dataset=crc.Dataset([ranking1,ranking2,ranking3])# or, from raw rankings that is a list of list of sets of either ints,or strsdataset2:crc.Dataset=crc.Dataset.from_raw_list([[{2,1},{4}],[{3,1,2},{4},{5}],[{1},{2},{3},{4}]])# or, create a Dataset object from a file where your rankings are stored# format file: each line is a list of either set, or list of int / str.dataset3:crc.Dataset=crc.Dataset.from_file(path="./dataset_examples/dataset_example")# print information about the datasetprint(dataset.description())# get all datasets in a folderlist_datasets:List[crc.Dataset]=crc.Dataset.get_datasets_from_folder(path_folder="./dataset_examples")fordataset_folderinlist_datasets:print(dataset_folder.description())# choose your scoring schemesc:crc.ScoringScheme=crc.ScoringScheme([[0.,1.,1.,0.,1.,1.],[1.,1.,0.,1.,1.,0.]])print("scoring scheme : "+str(sc))# scoring scheme descriptionprint(sc.description())print("\n### Consensus computation ###\n")# list of rank aggregation algorithms to use among  BioConsert, ParCons, ExactAlgorithm, KwikSortRandom,# RepeatChoice, PickAPerm, MedRank, BordaCount, BioCo, CopelandMethodalgorithms_to_execute=[crc.ExactAlgorithm(optimize=False),crc.KwikSortRandom(),crc.BioConsert(starting_algorithms=None),crc.BioConsert(starting_algorithms=[crc.CopelandMethod()]),crc.ParCons(bound_for_exact=90,auxiliary_algorithm=crc.BioConsert()),crc.CopelandMethod(),crc.BioCo(),crc.BordaCount(),]foralginalgorithms_to_execute:print(alg.get_full_name())consensus=alg.compute_consensus_rankings(dataset=dataset,scoring_scheme=sc,return_at_most_one_ranking=False)# to get the consensus rankings : consensus.consensus_rankings# description() will display supplementary informationprint(consensus.description())# if you want the consensus ranking only : print(consensus)# get the Kemeny score associated with the consensus:print(consensus.kemeny_score)# compute a Kemeny score between a ranking and a list of rankings (dataset object):ranking_test:crc.Ranking=crc.Ranking([{1,2},{4},{3}])dataset_test:crc.Dataset=crc.Dataset.from_raw_list([[{1},{2},{3},{4}],[{1,4},{3}]])scoring_scheme:crc.ScoringScheme=crc.ScoringScheme([[0.,1.,1.,0.,1.,0.],[1.,1.,0.,1.,1.,0.]])kemeny_obj:crc.KemenyComputingFactory=crc.KemenyComputingFactory(scoring_scheme)score:float=kemeny_obj.get_kemeny_score(ranking=ranking_test,dataset=dataset_test)print("\nscore = ",score)# Partitioning# consistent with at least one optimal consensusone_opt:crc.OrderedPartition=crc.OrderedPartition.parcons_partition(dataset_test,scoring_scheme)print(one_opt)# consistent with all the optimal consensusall_opt:crc.OrderedPartition=crc.OrderedPartition.parfront_partition(dataset_test,scoring_scheme)print(all_opt)Jupiter Notebook for code execution and more examplesMore detailed examples and use cases, please refer to ourJupyter Notebook.