lenskit.basic.topn.TopNRanker#

class lenskit.basic.topn.TopNRanker(config=None, **kwargs)#

Bases: lenskit.pipeline.components.Component[lenskit.data.ItemList]

Rank scored items by their score and take the top N. The ranking length can be passed either at runtime or at component instantiation time, with the latter taking precedence.

Stability:
Caller (see Stability Levels).
Parameters:
  • config (object | None)

  • kwargs (Any)

config: TopNConfig#

Configuration object.

__call__(*, items, n=None)#

Rank the items.

Parameters:
  • items (lenskit.data.ItemList) – The items to rank, with scores. Items with missing scores are not included in the final ranking.

  • n (int | None) – The number of items to return, or -1 to return all scored items. If None, the length configured at construction time is used.

Returns:

An ordered list of items, with scores and all other attributes preserved.

Return type:

lenskit.data.ItemList