Skip to content

DOC add example demonstrating NDCG, Kendall's tau and Spearman's rho for ranking evaluation - #34427

Open
Arraddhyyad wants to merge 2 commits into
scikit-learn:mainfrom
Arraddhyyad:add-ranking-metrics-example
Open

Arraddhyyad wants to merge 2 commits into
scikit-learn:mainfrom
Arraddhyyad:add-ranking-metrics-example

Conversation

@Arraddhyyad

@Arraddhyyad Arraddhyyad commented Jul 3, 2026 •

Copy link
Copy Markdown

Reference Issue

Closes #21138

What does this implement/fix?

Adds a new example, plot_ranking_metrics.py, under examples/model_selection/,
that shows how to evaluate a ranking-style problem using three metrics:

  • NDCG (sklearn.metrics.ndcg_score)
  • Kendall's tau (scipy.stats.kendalltau)
  • Spearman's rho (scipy.stats.spearmanr)

The example simulates a ranking dataset by generating a regression dataset and
splitting it into groups (queries), trains a GradientBoostingRegressor, evaluates
it on held-out test queries with all three metrics, and includes a short discussion
of when to use NDCG versus Kendall's tau / Spearman's rho.

This addresses the original code snippet in the issue, which passed
kendalltau/spearmanr directly into make_scorer — those functions return a
(statistic, pvalue) tuple, so the example wraps them to return only the
statistic.

Notes for reviewers

This is my first contribution to scikit-learn — happy to adjust the folder
location, dataset choice, or level of detail in the explanations based on
feedback.

AI usage disclosure

I used AI assistance while drafting and understanding this example, then tested and reviewed the code myself.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

Thank you for opening your first pull request to scikit-learn! 🎉

To help get your contribution reviewed, please make sure that:

  • You have filled out the pull request template.
  • The pull request addresses an existing issue that is ready for
    contribution (e.g. not tagged as "Needs Triage", "Needs Decision", ...).
    If you are proposing a new feature, please open an issue to discuss it first.
  • There are no other open pull requests already targeting the same issue.
  • You have followed the pull request checklist.
    In particular, linting and tests should pass.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Example with ranking metrices

1 participant