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:
pipeline (Pipeline) – The pipeline to run.
query (RecQuery | int | str | bytes | integer[Any] | str_ | bytes_ | object_ | ItemList | None) – The user ID or other query data for the recommendation.
n (int | None) – The number of items to recommend.
items (ItemList | Sequence[int | str | bytes | integer[Any] | str_ | bytes_ | object_] | ndarray[tuple[int], dtype[integer[Any] | str_ | bytes_ | object_]] | pd.Series[CoreID] | None) – The candidate items, or
None
to use the pipeline’s default candidate selector.component (str) – The name of the component implementing the recommender.
- 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.- Parameters:
pipeline (Pipeline) – The pipeline to run.
query (RecQuery | int | str | bytes | integer[Any] | str_ | bytes_ | object_ | ItemList | None) – The user ID or other query data for the recommendation.
items (ItemList | Sequence[int | str | bytes | integer[Any] | str_ | bytes_ | object_] | ndarray[tuple[int], dtype[integer[Any] | str_ | bytes_ | object_]] | pd.Series[CoreID]) – The candidate items, or
None
to use the pipeline’s default candidate selector.component (str) – The name of the component implementing the scorer.
- 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.- Parameters:
pipeline (Pipeline)
query (RecQuery | int | str | bytes | integer[Any] | str_ | bytes_ | object_ | ItemList | None)
items (ItemList | Sequence[int | str | bytes | integer[Any] | str_ | bytes_ | object_] | ndarray[tuple[int], dtype[integer[Any] | str_ | bytes_ | object_]] | pd.Series[CoreID])
component (str)
- Return type: