lenskit.knn.item#
Item-based k-NN collaborative filtering.
Classes#
Configuration for |
|
Item-item nearest-neighbor collaborative filtering feedback. This item-item |
Module Contents#
- class lenskit.knn.item.ItemKNNConfig#
Bases:
pydantic.BaseModelConfiguration for
ItemKNNScorer.- max_nbrs: pydantic.PositiveInt#
The maximum number of neighbors for scoring each item.
- min_nbrs: pydantic.PositiveInt = 1#
The minimum number of neighbors for scoring each item.
- min_sim: pydantic.PositiveFloat = 1e-06#
Minimum similarity threshold for considering a neighbor. Must be positive; if less than the smallest 32-bit normal (\(1.175 \times 10^{-38}\)), is clamped to that value.
- save_nbrs: pydantic.PositiveInt | None = None#
The number of neighbors to save per item in the trained model (
Nonefor unlimited).
- feedback: lenskit.data.FeedbackType = 'explicit'#
The type of input data to use (explicit or implicit). This affects data pre-processing and aggregation.
- 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:
Exported Aliases#
- class lenskit.knn.item.Dataset#
Re-exported alias for
lenskit.data.Dataset.
- lenskit.knn.item.FeedbackType#
Re-exported alias for
lenskit.data.FeedbackType.
- class lenskit.knn.item.ItemList#
Re-exported alias for
lenskit.data.ItemList.
- lenskit.knn.item.QueryInput#
Re-exported alias for
lenskit.data.QueryInput.
- class lenskit.knn.item.RecQuery#
Re-exported alias for
lenskit.data.RecQuery.
- class lenskit.knn.item.Vocabulary#
Re-exported alias for
lenskit.data.Vocabulary.
- class lenskit.knn.item.SparseRowArray#
Re-exported alias for
lenskit.data.matrix.SparseRowArray.
- exception lenskit.knn.item.DataWarning#
Re-exported alias for
lenskit.diagnostics.DataWarning.
- class lenskit.knn.item.Stopwatch#
Re-exported alias for
lenskit.logging.Stopwatch.
- lenskit.knn.item.get_logger()#
Re-exported alias for
lenskit.logging.get_logger().
- lenskit.knn.item.item_progress()#
Re-exported alias for
lenskit.logging.item_progress().
- lenskit.knn.item.trace()#
Re-exported alias for
lenskit.logging.trace().
- lenskit.knn.item.cur_memory()#
Re-exported alias for
lenskit.logging._resource.cur_memory().
- lenskit.knn.item.max_memory()#
Re-exported alias for
lenskit.logging._resource.max_memory().
- lenskit.knn.item.ensure_parallel_init()#
Re-exported alias for
lenskit.parallel.ensure_parallel_init().
- class lenskit.knn.item.Component#
Re-exported alias for
lenskit.pipeline.Component.
- class lenskit.knn.item.Trainable#
Re-exported alias for
lenskit.training.Trainable.
- class lenskit.knn.item.TrainingOptions#
Re-exported alias for
lenskit.training.TrainingOptions.