Skip to main content

Compute rankings in Python.

Project description

Ranky

Compute rankings in Python.

Build Status

logo

Get started

pip install ranky
import ranky as rk

Read the documentation.

Main functions

The main functionalities include scoring metrics (e.g. accuracy, roc auc), rank metrics (e.g. Kendall Tau, Spearman correlation), ranking systems (e.g. Majority judgement, Kemeny-Young method) and some measurements (e.g. Kendall's W coefficient of concordance).

Most functions takes as input 2-dimensional numpy.array or pandas.DataFrame objects. DataFrame are the best to keep track of the names of each data point.

Let's consider the following preference matrix:

matrix

Each row is a candidate and each column is a judge. Here is the results of rk.borda(matrix), computing the mean rank of each candidate:

borda

We can see that candidate2 has the best average rank among the four judges.

Let's display it using rk.show(rk.borda(matrix)):

display

Ranking systems

The rank aggregation methods available include:

  • Random Dictator: rk.dictator(m)
  • Score Voting: rk.score(m)
  • Borda Count: rk.borda(m)
  • Majority Judgement: rk.majority(m)
  • Condorcet, p-value Condorcet: rk.condorcet(m), rk.condorcet(m, wins=rk.p_wins)
  • Optimal rank aggregation using any rank metric: rk.center(m), rk.center(m, method='kendalltau'). Solver used [1].
  • (Kemeny-Young method is optimal rank aggregation using Kemeny distance as metric.)
  • (Optimal rank aggregation using Spearman correlation as metric is equivalent to Borda count.)

Metrics

You can use any_metric(a, b, method) to call a metric from any of the three categories below.

  • Scoring metrics: rk.metric(y_true, y_pred, method='accuracy'). Methods include: ['accuracy', 'balanced_accuracy', 'precision', 'average_precision', 'brier', 'f1_score', 'mxe', 'recall', 'jaccard', 'roc_auc', 'mse', 'rmse', 'sar']

  • Rank correlation coefficients: rk.corr(r1, r2, method='spearman'). Methods include: ['kendalltau', 'spearman', 'pearson']

  • Rank distances: rk.dist(r1, r2, method='levenshtein'). Methods include: ['hamming', 'levenshtein', 'winner', 'euclidean']

To add: general edit distances, kemeny distance, regression metrics...

Visualizations

  • Use rk.show to visualize preference matrix (2D) or ranking ballots (1D).

>>> rk.show(m)

show example 1

>>> rk.show(m['judge1'])

show example 2

  • Use rk.mds, to visualize (in 2D or 3D) the points in a given metric space. See rk.scatterplot documentation for display arguments.

>>> rk.mds(m, method='euclidean')

MDS example 1

>>> rk.mds(m, method='spearman', axis=1)

MSE example 2

  • You can use rk.tsne similarly to rk.mds.

Other

  • Rank, rk.rank, convert a 1D score ballot into a ranking.
  • Bootstrap, rk.bootstrap, sample a given axis.
  • Consensus, rk.consensus, check if ranking exactly agree.
  • Concordance, ,rk.concordance, mean rank distance between all judges of a preference matrix.
  • Centrality, rk.centrality, mean rank distance between a ranking and a preference matrix.
  • Kendall's W, rk.kendall_w, coefficient of concordance.
  • Utility: read_codalab_csv to parse a CSV generated by Codalab representing a leaderboard into a pandas.DataFrame.

References

Please cite ranky in your publications if this is useful for your research. Here is an example BibTeX entry:

@misc{pavao2020ranky,
  title={ranky},
  author={Adrien Pavao},
  year={2020},
  howpublished={\url{https://github.com/didayolo/ranky}},
}

[1] Storn R. and Price K., Differential Evolution - a Simple and Efficient Heuristic for Global Optimization over Continuous Spaces, Journal of Global Optimization, 1997, 11, 341 - 359.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

ranky-0.1.1-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file ranky-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ranky-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 18.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for ranky-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 38128e357100d25b9cb1d6cd6ab041d1a19022046ade51f19711f33c3d4676d6
MD5 21de8ba00d5d6608cb9a89ca4836f27a
BLAKE2b-256 7dbd81b90434c7c0afcbb698f1667012ea9a7d81862f60ec6fa2cb321cc2e15d

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page