Operation Functions#

The lenskit.operations module defines convenience functions for various recommender operations, simplifying the calls to the underlying pipeline. Each of these functions takes a pipeline, along with some parameters (e.g. the user ID or query), and runs the pipeline with those options.

These functions are re-exported from the top level lenskit package, so you can directly import them:

from lenskit import recommend, score

Recommending#

This function is the primary recommendation function to obtain a list of recommended items.

lenskit.operations.recommend(pipeline, query, n=None, items=None, *, component='recommender')#

Generate recommendations for a user or query. This calls the specified pipeline component (the 'recommender' by default) and returns the resulting item list.

Parameters:
Return type:

ItemList

Scoring and Predicting#

These functions score individual items with respect to a query (e.g. a user ID or history); they differ only in their default component.

lenskit.operations.score(pipeline, query, items, *, component='scorer')#

Score items with respect to a user or query. This calls the specified pipeline component (the 'scorer' by default) and returns the resulting item list.

Parameters:
Return type:

ItemList

lenskit.operations.predict(pipeline, query, items, *, component='rating-predictor')#

Predict ratings for items. This is exactly like score(), except it defaults to the 'rating-predictor' component. In a standard pipeline, the rating predictor may have additional configuration such as fallbacks or transformations to ensure every item is scored and the scores are valid rating predictions; the scorer typically returns raw scores.

Parameters:
Return type:

ItemList