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
Stability: Full
This API is at the full stability level; breaking changes for both callers and implementers will be reserved for annual major version bumps. See Stability Levels for details.
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.- Stability:
- Full (see Stability Levels).
- Parameters:
pipeline (Pipeline) – The pipeline to run.
query (QueryInput) – The user ID or other query data for the recommendation.
n (int | None) – The number of items to recommend.
items (ItemList | IDSequence | None) – The candidate items, or
None
to use the pipeline’s default candidate selector.component (str) – The name of the component implementing the recommender.
- Returns:
The recommended items as an ordered item list.
- Return type:
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.- Stability:
- Full (see Stability Levels).
- Parameters:
- Returns:
The items with scores in the
score
field.- Return type:
- 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.- Stability:
- Full (see Stability Levels).
- Parameters:
- Return type: