lenskit.knn.item.ItemKNNScorer ============================== .. py:class:: lenskit.knn.item.ItemKNNScorer(config = None, **kwargs) Bases: :py:obj:`lenskit.pipeline.Component`\ [\ :py:obj:`lenskit.data.ItemList`\ ], :py:obj:`lenskit.training.Trainable` Item-item nearest-neighbor collaborative filtering feedback. This item-item implementation is based on the description of item-based CF by :cite:t:`deshpande:iknn` and hard-codes several design decisions found to work well in the previous Java-based LensKit code :cite:p:`lenskit-java`. 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., :class:`~lenskit.basic.UserTrainingHistoryLookup`). :Stability: Caller .. py:attribute:: config :type: 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. .. py:attribute:: items :type: lenskit.data.Vocabulary Vocabulary of item IDs. .. py:attribute:: item_means :type: numpy.ndarray[tuple[int], numpy.dtype[numpy.float32]] | None Mean rating for each known item. .. py:attribute:: item_counts :type: numpy.ndarray[tuple[int], numpy.dtype[numpy.int32]] Number of saved neighbors for each item. .. py:attribute:: sim_matrix :type: lenskit.data.matrix.SparseRowArray Similarity matrix (sparse CSR tensor). .. py:method:: is_trained() Query if this component has already been trained. .. py:method:: train(data, options = TrainingOptions()) Train a model. The model-training process depends on ``save_nbrs`` and ``min_sim``, but *not* on other algorithm parameters. :param ratings: (user,item,rating) data for computing item similarities. .. py:method:: __call__(query, items) Run the pipeline's operation and produce a result. This is the key method for components to implement.