lenskit.knn.user.UserKNNScorer ============================== .. py:class:: lenskit.knn.user.UserKNNScorer(config = None, **kwargs) Bases: :py:obj:`lenskit.pipeline.Component`\ [\ :py:obj:`lenskit.data.ItemList`\ ], :py:obj:`lenskit.training.Trainable` User-user nearest-neighbor collaborative filtering with ratings. This user-user implementation is not terribly configurable; it hard-codes design decisions found to work well in the previous Java-based LensKit code. .. 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: UserKNNConfig 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:: users :type: lenskit.data.Vocabulary The index of user IDs. .. py:attribute:: items :type: lenskit.data.Vocabulary The index of item IDs. .. py:attribute:: user_means :type: numpy.ndarray[tuple[int], numpy.dtype[numpy.float32]] | None Mean rating for each known user. .. py:attribute:: user_vectors :type: scipy.sparse.csr_array Normalized rating matrix (CSR) to find neighbors at prediction time. .. py:attribute:: user_ratings :type: lenskit.data.matrix.SparseRowArray Centered but un-normalized rating matrix (COO) to find neighbor ratings. .. py:method:: is_trained() Query if this component has already been trained. .. py:method:: train(data, options = TrainingOptions()) "Train" a user-user CF model. This memorizes the rating data in a format that is usable for future computations. :param ratings: (user, item, rating) data for collaborative filtering. :type ratings: pandas.DataFrame .. py:method:: __call__(query, items) Compute predictions for a user and items. :param user: the user ID :param items: the items to predict :type items: array-like :param ratings: the user's ratings (indexed by item id); if provided, will be used to recompute the user's bias at prediction time. :type ratings: pandas.Series :returns: scores for the items, indexed by item id. :rtype: pandas.Series