Code Monkey home page Code Monkey logo

rank_eval's Introduction

rank_eval

โšก๏ธ Introduction

rank_eval is a collection of fast ranking evaluation metrics implemented in Python, taking advantage of Numba for high speed vector operations and automatic parallelization.

โœจ Available Metrics

  • Hits
  • Precision
  • Recall
  • rPrecision
  • Mean Reciprocal Rank (MRR)
  • Mean Average Precision (MAP)
  • Normalized Discounted Cumulative Gain (NDCG)

The metrics have been tested against TREC Eval for correctness โ€” through a comparison with pytrec_eval.

The implemented metrics are up to 50 times faster than pytrec_eval and with a much lower memory footprint.

Please note that TREC Eval uses a non-standard NDCG implementation. To mimic its behaviour, pass trec_eval=True to rank_eval's ndcg function.

๐Ÿ”ง Requirements

  • Python 3
  • Numpy
  • Numba

๐Ÿ”Œ Installation

pip install rank_eval

๐Ÿ’ก Usage

from rank_eval import ndcg
import numpy as np

# Note that y_true does not need to be ordered
# Integers are documents IDs, while floats are the true relevance scores
y_true = np.array([[[12, 0.5], [25, 0.3]], [[11, 0.4], [2, 0.6]]])
y_pred = np.array(
    [
        [[12, 0.9], [234, 0.8], [25, 0.7], [36, 0.6], [32, 0.5], [35, 0.4]],
        [[12, 0.9], [11, 0.8], [25, 0.7], [36, 0.6], [2, 0.5], [35, 0.4]],
    ]
)
k = 5

ndcg(y_true, y_pred, k, threads=1)
>>> 0.7525653965843032

rank_eval supports the usage of y_true elements of different lenght by using Numba Typed List. Simply convert your y_true list of arrays using the provided utility function:

from rank_eval import ndcg
from rank_eval.utils import to_typed_list
import numpy as np

y_true = [np.array([[12, 0.5], [25, 0.3]]), np.array([[11, 0.4], [2, 0.6], [12, 0.1]])]
y_true = to_typed_list(y_true)
y_pred = np.array(
    [
        [[12, 0.9], [234, 0.8], [25, 0.7], [36, 0.6], [32, 0.5], [35, 0.4]],
        [[12, 0.9], [11, 0.8], [25, 0.7], [36, 0.6], [2, 0.5], [35, 0.4]],
    ]
)
k = 5

ndcg(y_true, y_pred, k, threads=1)
>>> 0.786890544287473

๐Ÿ“š Documentation

Search the documentation for more details and examples.

๐ŸŽ“ Citation

If you end up using rank_eval to evaluate results for your sceintific publication, please consider citing it:

@misc{rankEval2021,
  title = {Rank\_eval: Blazing Fast Ranking Evaluation Metrics in Python},
  author = {Bassani, Elias},
  year = {2021},
  publisher = {GitHub},
  howpublished = {\url{https://github.com/AmenRa/rank_eval}},
}

๐ŸŽ Feature Requests

If you want a metric to be added, please open a new issue.

๐Ÿค˜ Want to contribute?

If you want to contribute, please drop me an e-mail.

๐Ÿ“„ License

rank_eval is an open-sourced software licensed under the MIT license.

rank_eval's People

Contributors

amenra avatar

Stargazers

SIV4K avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.