ranker.py module

class Ranker

Bases: object

A utility for ranking items based on their scores. The Ranker struct takes a ImproveAI model to evaluate and rank the given items.

property scorer

A Scorer is used to calculate scores for items. Items must be JSON encodable. If both scorer and model_url are provided scorer is preferred.

Returns:

a Scorer object for this Ranker

Return type:

Scorer

property model_url

URL or local FS path leading to Improve AI booster to be used with this scorer. Allows both raw xgboost files (most commonly having *.xgb extension) as well as gzipped boosters (*.xgb.gz). If both scorer and model_url are provided to Ranker’s constructor scorer is preferred. Can only be set during object initialization.

Returns:

model URL for this Ranker

Return type:

str

__init__(scorer=None, model_url=None)

Init Ranker with params. Either scorer or model_url must be provided. If both are provided Scorer is preferred.

Parameters:
  • scorer (Scorer) – a Scorer object to be used with this Ranker

  • model_url (str) – URL or local FS of a plain or gzip compressed Improve AI model resource

rank(items, context=None)

Ranks items and returns them ordered best to worst

Parameters:
  • items (list or tuple or np.ndarray) – list of items to be ranked

  • context (object) – any JSON encodable extra context info that will be used with each of the item to get its score

Returns:

a collection of ranked items, sorted by their scores in descending order.

Return type:

list or tuple or np.ndarray