lenskit.knn.item.ItemKNNScorer#
- class lenskit.knn.item.ItemKNNScorer(config=None, **kwargs)#
Bases:
lenskit.pipeline.Component[lenskit.data.ItemList],lenskit.training.TrainableItem-item nearest-neighbor collaborative filtering feedback. This item-item implementation is based on the description of item-based CF by Deshpande and Karypis [DK04] and hard-codes several design decisions found to work well in the previous Java-based LensKit code [ELKR11]. In explicit-feedback mode, its output is equivalent to that of the Java version.
Note
This component must be used with queries containing the user’s history, either directly in the input or by wiring its query input to the output of a user history component (e.g.,
UserTrainingHistoryLookup).- Stability:
- Caller (see Stability Levels).
- Parameters:
config (object | None)
kwargs (Any)
- config: ItemKNNConfig#
The component configuration object. Component classes that support configuration must redefine this attribute with their specific configuration class type, which can be a Python dataclass or a Pydantic model class.
- items: lenskit.data.Vocabulary#
Vocabulary of item IDs.
- item_means: numpy.ndarray[tuple[int], numpy.dtype[numpy.float32]] | None#
Mean rating for each known item.
- item_counts: numpy.ndarray[tuple[int], numpy.dtype[numpy.int32]]#
Number of saved neighbors for each item.
- sim_matrix: lenskit.data.matrix.SparseRowArray#
Similarity matrix (sparse CSR tensor).
- is_trained()#
Query if this component has already been trained.
- train(data, options=TrainingOptions())#
Train a model.
The model-training process depends on
save_nbrsandmin_sim, but not on other algorithm parameters.- Parameters:
ratings – (user,item,rating) data for computing item similarities.
data (lenskit.data.Dataset)
options (lenskit.training.TrainingOptions)
- __call__(query, items)#
Run the pipeline’s operation and produce a result. This is the key method for components to implement.
- Parameters:
query (lenskit.data.QueryInput)
items (lenskit.data.ItemList)
- Return type: